Answer the question
In order to leave comments, you need to log in
What are the ways to create real data models in angularjs?
I use angularJS, I always just threw the data received from the server into the rootscope, which are needed in several places in the application. There was a time, I decided to issue normally. Since REST communication with the server, I took the restangular library (no questions about it, it works fine, although someone may suggest more interesting options). I would like to make models like on the backend, a separate class (factory, service) with methods for getting save, processing output for various places. Using the model according to the Singleton principle - initialize once, and use the data in different places, when changing in the model, so that it changes throughout the application where the model outputs data.
But I can't find an answer to my problem.
Code example, how I imagine the model works.
angular.module('Start').factory('User', function(Restangular, $rootScope) {
var User = function() {
then = this;
return data = _resource.get('current').then(function(result){
console.log(result);
then.data = result;
});
};
var _resource = Restangular.all('users');
var data;
return User;
});
var res = User();
console.log(res .data);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question