我可以访问模板中的AngularJS模块配置值吗?
我想在我可以访问模板中的AngularJS模块配置值吗?,angularjs,angular-ui-router,Angularjs,Angular Ui Router,我想在home.tpl.html模板中访问一个特殊值。这可以作为{{magicHappened.mySpecialValue}完成吗?如果可以,如何完成?该值是state()中的最后一个参数 当然,如果有更好的办法,请告诉我 angular.module('myModule', [ 'ui.router' ]) .config(function homeConfig($stateProvider, $urlRouterProvider, $locationProvider) { $sta
home.tpl.html
模板中访问一个特殊值。这可以作为{{magicHappened.mySpecialValue}
完成吗?如果可以,如何完成?该值是state()
中的最后一个参数
当然,如果有更好的办法,请告诉我
angular.module('myModule', [
'ui.router'
])
.config(function homeConfig($stateProvider, $urlRouterProvider, $locationProvider) {
$stateProvider
.state('home', {
url: '/',
templateUrl: '/app/home/home.tpl.html',
controller: 'HomeCtrl',
pageTitle: 'Home',
mySpecialValue: 'thisValueHere'
});
$urlRouterProvider.otherwise('/');
$locationProvider.html5Mode(true);
});
您可以使用
数据
进行配置。见:
然后在你的控制器里
.controller('HomeCtrl',
[ '$scope', '$state',
function ($scope, $state) {
$scope.mySetting = $state.current.data.mySpecialValue;
...
在你看来,这可能像是
{{mySetting}
是的,我差不多就是这样做的。:)我使用了$scope.on($stateChangeSuccess,function(event,toState){//与您的代码非常相似});非常感谢你的链接。这是理想的。
.controller('HomeCtrl',
[ '$scope', '$state',
function ($scope, $state) {
$scope.mySetting = $state.current.data.mySpecialValue;
...