i changed my service (model) to use with this, and now is giving this bizarre error , I searched and found that it would be for syntax error, the value would not be returning, but I think in my case the problem is not this.
The error is:
Provider 'EventModel' must return a value from $get factory method.
And that's my code:
'use strict';
var EventModel = function($http) {
this.url = 'http://localhost:3000/api/events';
this.$http = $http;
};
EventModel.prototype = {
find: function() {
return this.$http.get(this.url).then(this.extract);
},
extract: function(result) {
return result.data;
}
};
angular
.module('siteApp')
.factory('EventModel', [
'$http',
EventModel
]);
What could be?
Thanks.
With the way you have defined what you need to use is a service
recipe and not factory
.
ie
angular
.module('siteApp')
.service('EventModel', ['$http', EventModel]);
If you register with a factory recipe the constructor needs to return the instance, in your case you are not returning anything, and no new
ing up happens for factory recipe. Instead what you have a proper constructor and with your implementation you are typically looking for it to be called with new
operator and which is what precisely a service
recipe does.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.