刷官方中文angularJs手册例子( 二 )


控制器
function PhoneDetailCtrl($scope, $routeParams) {$scope.phoneId = $routeParams.phoneId;}
路由规则如下
angular.module('phonecatApp').config(['$routeProvider',function config($routeProvider) {$routeProvider.when('/phones', {template: ''}).when('/phones/:phoneId', {template: ''}).otherwise('/phones');}]);
创建模块注入$服务提供配置路由规则
注意事项:
为了让我们的应用引导我们新创建的模块,我们同时需要在[ngApp]指令的值上指明模块的名字
app/index.html
...
模板
$route服务通常和[]指令一起使用 。指令的角色是为当前路由把对应的视图模板载入到布局模板中
如下所示
...="lib/angular/angular.js">="js/app.js">="js/controllers.js">


删除的模板放置在phone-list.html中