unknown provider when injecting an object in controller, object from resolve method

4,225 views
Skip to first unread message

Keisha Gaspard

unread,
Oct 8, 2013, 5:25:47 PM10/8/13
to ang...@googlegroups.com
Hey guys,

I'm really stumped, I've looked at teh following blogs: here and here and they seem to be doing the same as I, I am using angular 1.0.7 and keep getting the error:
Error: [$injector:unpr] Unknown provider: completedGoalsProvider <- completedGoals at hasOwnPropertyFn (http://localhost:8090/myproject/resources/mobileWeb/libs/angular_1.2.0rc1/angular.js:60:12)

Here is some of my code excerpt:

 
app.js
angular.module('myproject').config(['$routeProvider','RESOURCE_PATH','URI_PATH',function($routeProvider,RESOURCE_PATH,URI_PATH) {
$routeProvider
.when(URI_PATH.goals, {
controller: 'MyGoalsCtrl',
templateUrl: RESOURCE_PATH+'my_goals/partials/my_goals.tpl',
resolve: {
completedGoals: function($q, MyGoalsService){
var deferred = $q.defer();
MyGoalsService.query({goalType:"completed"}, function(successData){
deferred.resolve(successData);
}, function(errorData){
//Update screen to display message as to why page load cannot occur
deferred.reject();
});
return deferred.promise;
},
incompleteGoals: function($q, MyGoalsService){
var deferred = $q.defer();
MyGoalsService.query({goalType:"incomplete"}, function(successData){
deferred.resolve(successData);
}, function(errorData){
deferred.reject();
});
return deferred.promise;
}
}
});

Controller:
var myGoalsCtrl = myproject.controller('MyGoalsCtrl',function ($scope, $log, MyGoalsService, completedGoals, incompleteGoals){

// need to retrieve two sets of data.
var completedStatus = "completed";
var incompleteStatus = "incomplete";

// and get the goals which I have done
$scope.goalTemplates = goalTemplates;
$scope.completedGoals = completedGoals;
$scope.incompleteGoals = incompleteGoals;
}

When I step through the code and hover over completedGoals and incompleteGoals, they are populated with goals and are resolved, however at the end of teh controller it throws the error unknownProvider completedGoalsProvider.


Please help!


OpenNota

unread,
Oct 8, 2013, 6:20:35 PM10/8/13
to ang...@googlegroups.com
  I am using angular 1.0.7


Oh, really? Can you post a working example, demonstrating your problem? 

agileDev

unread,
Oct 9, 2013, 10:11:51 AM10/9/13
to ang...@googlegroups.com
Thanks! Nice catch angular 1.2.0.

I have to get a plunkr up but this is the jist of it, the properties resolve but at the end of the controller's initialization it throws the unknown provider exception. 

agileDev

unread,
Oct 9, 2013, 10:28:09 AM10/9/13
to ang...@googlegroups.com
This is the plunkr I am working on with the resolve: http://plnkr.co/edit/3CLmaW5ksjdDzcl2icbo?p=preview

agileDev

unread,
Oct 9, 2013, 10:36:54 AM10/9/13
to ang...@googlegroups.com
I saw this example: http://jsfiddle.net/derkoe/Wk7WD/

Where he stored the data in a variable in the service, so "load" isn't really injected into the controller but it is bound by the service - is this a best practice? 

Thanks guys! Really new to all this.


On Wednesday, October 9, 2013 10:11:51 AM UTC-4, agileDev wrote:

OpenNota

unread,
Oct 9, 2013, 10:43:54 AM10/9/13
to ang...@googlegroups.com
Aha, got it. You only need to specify controller once, in app.js. The second one, in the html code, is instantiated by the ngController directive, which does not know about `resolve', so it throws an exception.

agileDev

unread,
Oct 9, 2013, 10:49:22 AM10/9/13
to ang...@googlegroups.com
Hmm...I'm not sure I understand, am I doing something wrong in app.js then? or is it that I shouldn't be injecting properties defined in the resolve in the controller?

OpenNota

unread,
Oct 9, 2013, 11:07:46 AM10/9/13
to ang...@googlegroups.com
Just remove ng-controller="..." from your html. This second controller NOT injected with goals.

agileDev

unread,
Oct 9, 2013, 11:16:15 AM10/9/13
to ang...@googlegroups.com
Eurika!! Yes that was it, you're a genius @OpenNota. Thank you so much :)

Perry Gollo

unread,
Feb 15, 2015, 12:01:58 PM2/15/15
to ang...@googlegroups.com
I love you guys!!

have been banging my head for hours...

songtory

unread,
Nov 12, 2015, 1:15:18 AM11/12/15
to AngularJS

oh my god!

Thank you man!!!


Reply all
Reply to author
Forward
0 new messages