http://angularjs.org/Cookbook:DeepLinking
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 31 Oct 2010 12:03:14 +0000 (13:03 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 31 Oct 2010 12:03:14 +0000 (13:03 +0100)
This example works from it's subdirectory when server is started with:

ANGULAR_JS=http://angularjs.org/ng/js/angular-debug.js ./angular-server.pl daemon --reload

to use upstream angular, but not with current version from git (but it
works from root of server)

templates/Cookbook/5-DeepLinking.html.ep [new file with mode: 0644]

diff --git a/templates/Cookbook/5-DeepLinking.html.ep b/templates/Cookbook/5-DeepLinking.html.ep
new file mode 100644 (file)
index 0000000..0c1602e
--- /dev/null
@@ -0,0 +1,44 @@
+<script>
+angular.service('myApplication', function($route){
+  // define routes
+  $route.when("",          {template:'/cb/welcome.html',  controller:WelcomeCntl});
+  $route.when("/settings", {template:'/cb/settings.html', controller:SettingsCntl});
+
+  // initialize the model to something useful
+  this.person = {
+   name:'anonymous',
+   contacts:[{type:'email', url:'anonymous@example.com'}]
+  };
+ }, {inject:['$route']});
+
+ function WelcomeCntl(){}
+ WelcomeCntl.prototype = {
+  greet: function(){
+   alert("Hello " + this.person.name);
+  }
+ };
+
+ function SettingsCntl(){
+  this.cancel();
+ }
+ SettingsCntl.prototype = {
+  cancel: function(){
+   this.form = angular.copy(this.person);
+  },
+
+  save: function(){
+   angular.copy(this.form, this.person);
+   window.location.hash = "#";
+  }
+ };
+</script>
+<h1>Your App Chrome</h1>
+[ <a href="#">Welcome</a> | <a href="#/settings">Settings</a> ]
+<hr/>
+<span style="background-color: blue; color: white; padding: 3px;">
+  Partial: {{$route.current.template}}
+</span>
+<div style="border: 1px solid blue; margin: 0;">
+  <ng:include src="$route.current.template" scope="$route.current.scope"></ng:include>
+</div>
+<small>Your app footer </small>