出于某种原因,当使用多个命名 View (angular-ui ui-router)时, Controller 看不到我的已解决数据。有没有人遇到过这个问题?
$stateProvider
.state('page',{
abstract: true,
templateUrl: ...,
controller: abstractController
})
.state('page.index',
url: '/page',
resolve : {
resolvedData: function(CONSTANTS){ return CONSTANTS.data;}
},
views: {
home: {templateUrl: ...,
controller: function(resolvedData){
....
}
},
list: {templateUrl: ...,
controller: function(resolvedData){
....
}
},
edit: {templateUrl: ...,
controller: function(resolvedData){
....
}
}
}
)
它给我的错误是:错误:[$injector:unpr] 未知提供者:resolvedDataProvider<-resolvedData。这在某种程度上很有趣,因为它只发生在一个 View 中,而不发生在其他 View 中。
最佳答案
我创建了 small working example ,表明你的东西应该工作
这将是常量:
.factory('CONSTANTS', function() {
return { data: { name : "some name", number : "some number"} };
})
和相同的(只是明确注释的 DI)状态定义:
// States
$stateProvider
.state('page', {
abstract: true,
template: '<div>'
+ '<div ui-view="home"></div>'
+ '<div ui-view="list"></div></div>',
controller: 'abstractController'
})
.state('page.index', {
url: '/page',
resolve: {
resolvedData: ['CONSTANTS',
function(CONSTANTS) {
return CONSTANTS.data;
}
]
},
views: {
home: {
templateUrl: 'tpl.html',
controller: ['resolvedData','$scope',
function(resolvedData, $scope) {
console.log(resolvedData);
$scope.resolvedData = resolvedData;
}
],
},
list: {
template: '<div>list view</div>'
}
}
})
所以,上面使用的决议草案是有效的。这是正确的方法......解析函数提供了一些服务......并返回其属性
data
.检查所有 here
关于angularjs - Angular-ui State - 多个 View 看不到我的解析数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28149061/