我试图通过使用State Provider
将数据传递到我的控制器。如何将数据从一个控制器传递到另一个控制器
我有这样的事情
app.js
$stateProvider
.state('test', {
url: '/te',
views: {
'': {
templateUrl: 'test.html',
controller: 'testCtrl'
},
data:{
testValue:true
}
}
})
我的控制器:
app.controller('mainTestCtrl', function($scope) {
//I need to be able to get the testValue from here.
})
app.controller('testCtrl', function($scope, $state) {
var testValue = $state.current.views.data.testValue;
})
我真的不能提供mainTestCtrl
国家提供,因为我需要测试值是true
只有当调用testCtrl
时。我需要一种方法将testValue传递给mainTestCtrl。有没有办法做到这一点?谢谢。
在其中'testCtrl'被实例化的一点,就是' mainTestCtrl'已经实例化自己? –
@Marc yes mainTestCtrl将在testCtrl之前实例化 – FlyingCat