I'm new to Angular and trying to figure out how to create a model to clean up my controller. I'm using Restangular and have created a factory that returns a model object.
I thought that I could do something like this...
model
Testimonials.factory('Testimonial', ['Restangular', function(Restangular) {
/**
* Constructor
*/
function Testimonial() {
// public properties, assigned to the instance ('this')
}
Testimonial.prototype.all = function() {
return Restangular.all('testimonials').getList();
}
/**
* Return the constructor function
*/
return Testimonial;
}]);
controller
Testimonials.controller('TestimonialsController', ['$scope', 'Testimonial', function($scope, Testimonial) {
Testimonial.all.then(function (testimonials) {
$scope.testimonials = testimonials;
});
}]);
I am receiving the error in chome dev tools, TypeError: Cannot read property 'then' of undefined
.
How can I make this work? And is this a good way to implement a model?