该data : {}
设置是静态的。
看到类似:
如果你想要一些动态特征利用resolve : {}
一些链接&关于解决例子和Q
EXTEND:一个简单的(真的很幼稚,但工作)例如如何使用resolve
和$rootScope
管理浏览器的标题(check it here):
$stateProvider
.state('home', {
url: "/home",
templateUrl: 'tpl.html',
resolve: {
'title': ['$rootScope', function($rootScope){
$rootScope.title = "Other title";
}],
}
})
.state('parent', {
url: "/parent",
templateUrl: 'tpl.html',
resolve: {
'title': ['$rootScope', function($rootScope){
$rootScope.title = "Title from Parent";
}],
}
})
.state('parent.child', {
url: "/child",
templateUrl: 'tpl.html',
controller: 'ChildCtrl',
resolve: {
'titleFromChild': ['$rootScope', function($rootScope){
$rootScope.title = "Title from Child";
}],
}
})
而且这可能是HTML
<!DOCTYPE html>
<html ng-app="MyApp" ng-strict-di>
<head>
<title>{{title}}</title>
试一试here
这里的挑战是 - 什么对导航执行从子到父,但它可以通过移动设置到控制器,并与$scope.$on('detsroy'
工作要做......
这里是adjusted plunker
.state('parent.child', {
url: "/child",
templateUrl: 'tpl.html',
controller: 'ChildCtrl',
// no resolve, just controller fills the target
})
.controller('ChildCtrl', ['$rootScope', '$scope', function ($rootScope, $scope) {
var title = $rootScope.title;
$rootScope.title = "Title from Child";
$scope.$on('$destroy', function(){$rootScope.title = title});
}])
你想把'slug'放在你的浏览器标题上吗?但那么其他州的标题是什么呢? –