由于某种原因,当使用多个命名视图(angular-ui ui-router)时,控制器看不到我的solveData。有人遇到过这个问题吗?
$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] 未知提供程序:solveDataProvider <- solveData。这在某种程度上很有趣,因为它只发生在其中一个视图中,而不是在其他视图中。
我创建了一个小的工作示例,表明你的东西应该可以工作
这将是常量:
.factory('CONSTANTS', function() {
return { data: { name : "some name", number : "some number"} };
})
和相同的(只是明确注释的 DI)状态 def:
// 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
。
检查所有在这里