diff options
Diffstat (limited to 'docs/content/cookbook/deeplinking.ngdoc')
| -rw-r--r-- | docs/content/cookbook/deeplinking.ngdoc | 27 | 
1 files changed, 24 insertions, 3 deletions
| diff --git a/docs/content/cookbook/deeplinking.ngdoc b/docs/content/cookbook/deeplinking.ngdoc index 7d69ee84..cc748b3f 100644 --- a/docs/content/cookbook/deeplinking.ngdoc +++ b/docs/content/cookbook/deeplinking.ngdoc @@ -3,14 +3,18 @@  @name Cookbook: Deep Linking  @description +  Deep linking allows you to encode the state of the application in the URL so that it can be  bookmarked and the application can be restored from the URL to the same state. +  While <angular/> does not force you to deal with bookmarks in any particular way, it has services  which make the common case described here very easy to implement. +  # Assumptions +  Your application consists of a single HTML page which bootstraps the application. We will refer  to this page as the chrome.  Your application is divided into several screens (or views) which the user can visit. For example, @@ -21,23 +25,30 @@ screen will be constructed from an HTML snippet, which we will refer to as the p  have multiple partials, but a single partial is the most common construct. This example makes the  partial boundary visible using a blue line. +  You can make a routing table which shows which URL maps to which partial view template and which  controller. +  # Example +  In this example we have a simple app which consist of two screens: +  * Welcome: url `#` Show the user contact information.  * Settings: url `#/settings` Show an edit screen for user contact information. + +  The two partials are defined in the following URLs:  * {@link ./examples/settings.html}  * {@link ./examples/welcome.html} +  <doc:example>   <doc:source>      <script> @@ -48,6 +59,7 @@ The two partials are defined in the following URLs:        $route.when("/settings", {template:'./examples/settings.html', controller:SettingsCntl});        $route.parent(this); +        // initialize the model to something useful        this.person = {         name:'anonymous', @@ -55,6 +67,7 @@ The two partials are defined in the following URLs:        };       } +       function WelcomeCntl($route){}       WelcomeCntl.prototype = {        greet: function(){ @@ -62,6 +75,7 @@ The two partials are defined in the following URLs:        }       }; +       function SettingsCntl(){        this.cancel();       } @@ -70,6 +84,7 @@ The two partials are defined in the following URLs:         this.form = angular.copy(this.person);        }, +        save: function(){         angular.copy(this.form, this.person);         window.location.hash = "#"; @@ -102,13 +117,19 @@ The two partials are defined in the following URLs: + + +  # Things to notice +  * Routes are defined in the `AppCntl` class. The initialization of the controller causes the -  initialization of the {@link angular.service.$route $route} service with the proper URL routes. -* The  {@link angular.service.$route $route} service then watches the URL and instantiates the +  initialization of the {@link api/angular.service.$route $route} service with the proper URL +routes. +* The  {@link api/angular.service.$route $route} service then watches the URL and instantiates the    appropriate controller when the URL changes. -* The  {@link angular.widget.ng:view ng:view} widget loads the view when the URL changes. It also +* The  {@link api/angular.widget.ng:view ng:view} widget loads the view when the URL changes. It +also    sets the view scope to the newly instantiated controller.  * Changing the URL is sufficient to change the controller and view. It makes no difference whether    the URL is changed programatically or by the user. | 
