我无法在控制器中注入ui路由的解析属性。 这是给为什么在使用ui-router注入控制器中解析的属性时出现提供程序错误?
错误:$注射器:unpr 未知提供商
当我使用状态定义对象控制器属性如下
.state('widget', {
url: '/widgets',
template: '<h1>{{name}}</h1>',
controller: function(widget, $scope) {
$scope.name = widget.name;
},
resolve: {
// standard resolve value promise definition
widget: function() {
return {
name: 'myWidget'
};
},
// resolve promise injects sibling promise
features: function(widget) {
return ['featureA', 'featureB'].map(function(feature) {
return widget.name+':'+feature;
});
}
}
});
然后,它工作正常,我能够在控制器中获得小部件,并且能够在html中使用。
请参阅小提琴的代码。
http://jsfiddle.net/sunilmadaan07/ugsx6c1w/8/
可能是我正在做一个愚蠢的错误。 在发布这个问题之前,我曾尝试用简单对象,承诺对象返回属性。
在此先感谢。
我已删除嵌套的决心从代码。 请看看 http://jsfiddle.net/sunilmadaan07/ugsx6c1w/13/ –
你不能在* nested * show-data组件中使用'widget'解析器。切换到UI路由器1.x并将其直接用作路由组件。 – estus