【发布时间】:2014-10-24 01:05:43
【问题描述】:
我正在尝试为我的控制器确定最佳实践。
我有多个控制器,我需要传递数据。
第一个控制器
app.controller('testCtr', ['$scope','$rootScope', function($scope, $rootScope) {
$scope.testdata = true;
}])
第二个控制器
app.controller('secondCtr', ['$scope','$rootScope', function($scope, $rootScope) {
var test = $rootscope.testdata;
}])
我的第二个选择是使用 $parent
第一个控制器
app.controller('testCtr', ['$scope','$rootScope', function($scope, $rootScope) {
$scope.testdata = true;
}])
第二个控制器
app.controller('secondCtr', ['$scope','$rootScope', function($scope, $rootScope) {
var test = $scope.$parent.$parent.testdata;
}])
我不确定最好的方法是什么。任何人?谢谢!
【问题讨论】:
-
您的控制器结构如何?我建议不要使用 $parent
标签: javascript angularjs angularjs-scope angularjs-service