使用UI路由器时,控制器可以继承父控制器范围 [英] Can a controller inherit scope from a parent controller when using ui-router
本文介绍了使用UI路由器时,控制器可以继承父控制器范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下内容:
VAR管理员= { 名称:'管理员',
网址:'/管理员',
观点:{
NAV-子:{
templateUrl:/Content/app/admin/partials/nav-sub.html',
控制器:函数($范围内){$ scope.message =你好; }
}
},
控制器:['$范围',函数($范围){
$ scope.message =你好;
}]
}无功受= {
名称:'主题',
父:管理员,
网址:'/主题',
观点:{
网@:{
templateUrl:/Content/app/admin/partials/grid-subject.html',
控制器:'AdminGridSubjectController',
}
}
};
我想AdminGridSubjectController知道$ scope.message价值是什么,但它似乎不知道这件事。是不是我做错了什么?
stApp.controller('AdminGridSubjectController',['$范围',函数($范围){
风险价值= $ scope.message;
}]);
解决方案
为了访问角UI路由器父控制器的范围
是:
$范围。$父
然后父范围,然后免费提供给你。
I have the following:
var admin = {
name: 'admin',
url: '/admin',
views: {
'nav-sub': {
templateUrl: '/Content/app/admin/partials/nav-sub.html',
controller: function ($scope) { $scope.message = "hello"; }
}
},
controller: ['$scope', function ($scope) {
$scope.message = "hello";
}]
}
var subject = {
name: 'subject',
parent: admin,
url: '/subject',
views: {
'grid@': {
templateUrl: '/Content/app/admin/partials/grid-subject.html',
controller: 'AdminGridSubjectController',
}
}
};
I would like the AdminGridSubjectController to know what the $scope.message value is but it seems not to know anything about it. Is there something I am doing wrong?
stApp.controller('AdminGridSubjectController', ['$scope', function ( $scope ) {
var a = $scope.message;
}]);
解决方案
In order to access the scope
of a parent controller in Angular UI Router use:
$scope.$parent
Then the parent scope is then freely available to you.
这篇关于使用UI路由器时,控制器可以继承父控制器范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文