我有一个API,我想解决名称为“泡沫”。这个我想注入控制器 - 但问题是,我已经尝试不同的方法和一切只是说...不确定和一些注射问题... :(
代码:
.state('bubbles', {
abstract: false,
url: "/bubbles/:bubbleId/feed",
controller: 'BubblesController',
data: {
authorizedRoles: [USER_ROLES.editor]
},
resolve: {
resolvedBubbleName: function ($http, $stateParams) {
var url = 'https://XXXXXXX.net/api/Bubble/11111111-1111-1111-1111-111111111111';
return $http.get(url)
.then(function (response) {
console.log('response ' + response);
return response;
});
},
views: {
'navigation': {
templateUrl: "/raqt/shared/partials/navigation.html"
},
'main': {
templateUrl: "/raqt/bubbles/partials/bubbles.html"
//controller: function ($scope, resolvedBubbleName) {
// $scope.resolvedBubbleName = resolvedBubbleName;
// // resolvedBubbleName is always undefined, i.e.,
// // UI router is not injecting it
//}
}
},
}
})
在我控制器我尝试不同的方法,这是我认为应该工作...给出错误注入......从页面
BubblesController.$inject = ['$stateParams', '$state', '$log', '$timeout', '$interval', '$scope', 'BubblesService', 'CONFIG', '$http', 'resolvedBubbleName'];
function BubblesController($stateParams, $state, $log, $timeout, $interval, $scope, BubblesService, CONFIG, $http, resolvedBubbleName) {
$scope.title = 'bubbles-controller';
alert(resolvedBubbleName);
$scope.bubbleId = $state.params.bubbleId;
错误
Error: [$injector:unpr] Unknown provider: resolvedBubbleNameProvider <- resolvedBubbleName <- BubblesController
http://errors.angularjs.org/1.3.15/$injector/unpr?p0=resolvedBubbleNameProvider%20%3C-%20resolvedBubbleName%20%3C-%20BubblesController
at REGEX_STRING_REGEXP (http://localhost:3604/js/lib/angular/angular.js:63:12)
at http://localhost:3604/js/lib/angular/angular.js:4015:19
at Object.getService [as get] (http://localhost:3604/js/lib/angular/angular.js:4162:39)
at http://localhost:3604/js/lib/angular/angular.js:4020:45
at getService (http://localhost:3604/js/lib/angular/angular.js:4162:39)
at Object.invoke (http://localhost:3604/js/lib/angular/angular.js:4194:13)
at $get.extend.instance (http://localhost:3604/js/lib/angular/angular.js:8493:21)
at http://localhost:3604/js/lib/angular/angular.js:7739:13
at forEach (http://localhost:3604/js/lib/angular/angular.js:331:20)
at nodeLinkFn (http://localhost:3604/js/lib/angular/angular.js:7738:11) <div ui-view="main" class="ng-scope">
我可以看到,$ HTTP调用是有数据的,我知道控制器效果很好,否则 - 但这决心把我逼疯.. :(
我会关闭几个小时 - 但我会回来的GE这个如果你看到在我的代码我将GE的一些问题回来,并回答!... :)
嗨,对不起,迟交回复。我试着看看你的代码,看着我的 - 而你的工作正常,但我仍然很奇怪的信息,注入是错误的。 错误:[$ injector:unpr]未知提供者:resolvedBubbleNameProvider < - resolvedBubbleName < - BubblesController http://errors.angularjs.org/1.3.15/$injector/unpr?p0= :( – MrWeiland
我扩展了我的答案, 2个更多的可疑场景,希望能对你有所帮助;) –
好 - 这太尴尬了 - 我用grunt和watcher进行文件和缩小...现在我想你知道发生了什么...我一直在编辑错误的文件,因为咕噜没有看到该文件正确! 今天下午当我回到家时,我将会考验你的解决方案..我很肯定这会起作用! :) – MrWeiland