javascript - Creating an object-oriented AngularJS model with Restangular -
i'm new angular , trying figure out how create model clean controller. i'm using restangular , have created mill returns model object.
i thought this...
model
testimonials.factory('testimonial', ['restangular', function(restangular) { /** * constructor */ function testimonial() { // public properties, assigned instance ('this') } testimonial.prototype.all = function() { homecoming restangular.all('testimonials').getlist(); } /** * homecoming constructor function */ homecoming testimonial; }]);
controller
testimonials.controller('testimonialscontroller', ['$scope', 'testimonial', function($scope, testimonial) { testimonial.all.then(function (testimonials) { $scope.testimonials = testimonials; }); }]);
i receiving error in chome dev tools, typeerror: cannot read property 'then' of undefined
.
how can create work? , way implement model?
in controller, missing parentheses in all
method:
change:
testimonial.all.then(function (testimonials) { $scope.testimonials = testimonials; });
to:
testimonial.all().then(function (testimonials) { $scope.testimonials = testimonials; });
and need homecoming new instance of testimonial
in factory:
change:
return testimonial;
to:
return new testimonial();
javascript angularjs restangular code-cleanup
No comments:
Post a Comment