我有一個使用Ui路由器進行路由的Angular應用程序。每次我更改路由器時,我都想更改頁面的標題,並且好像$ stateProvider是最簡單的方法。我有這樣的事情爲$ stateProvider:Angular UI路由器設置範圍/變量
$stateProvider
.state('index', {
url: "/",
views: {
"rightContainer": { templateUrl: "viewA.html" },
},
controller: function ($scope) {
$scope.data.header = "Header 1"
}
})
.state('details', {
url: "/details",
views: {
"rightContainer": { templateUrl: "ViewB.html" },
},
controller: function ($scope) {
$scope.data.header = "Header 2"
}
});
那麼我想有頭:
<div data-ng-controller="mainCtrl">
<div class='bg'>{{data.header}}</div>
</div>
可能,最好採用DA ta https://github.com/angular-ui/ui-router/wiki#attach-custom-data-to-state-objects – Whisher 2014-09-10 18:31:49