Reputation: 1740
I am trying to learn AngularJS. Whdile I was following the instructor, I wrote the same code as he did. But I am getting a [$injector:undef] Provider 'dataService' must return a value from $get factory method
error. When I searched for this error in web, it is told that I must return a function or an object. I guess I am doing it. My factory declaration is below:
module.factory("dataService", ['$http', '$q', function ($http, $q) {
var _topics = [];
var _getTopics = function () {
var deferred = $q.defer();
$http.get("/api/v1/topics?includeReplies=true")
.then(function (result) {
//success
angular.copy(result.data, _topics);
deferred.resolve();
},
function () {
//error
deferred.reject();
});
return deferred.promise;
};
return
{
topics: _topics;
getTopics: _getTopics;
};
}]);
Any helps are appreciated...
Upvotes: 2
Views: 12149
Reputation: 7958
There's a syntax error in you code in the return statement. You should use a comma to separate the properties of the object. It should be:
return {
topics: _topics,
getTopics: _getTopics
};
Based on the comment thread, the ultimate solution appears to have been removing the line break between return
and {
. See this answer for more explanation.
Upvotes: 9