B
B
Bogopodoben2016-09-14 09:10:39
Angular
Bogopodoben, 2016-09-14 09:10:39

How to form the correct Angularjs 1.x data model?

This question has been discussed many times already, I looked, but I did not find a clear answer anywhere.
How to properly structure the model for working with data? namely, the essence of the problem, so that with each change in data, the appearance of a new event, etc., the data is updated and the user sees all the changes after saving, deleting, adding.
It would be really not bad to tell point by point how an adequate model should look like, how an adequate model should work.
Or throw good articles, books, where this topic is chewed.
One of the useful articles:
At the moment, all requests from the server are executed in the service:

angular.module('app.user.projects')
.service('ApiProjects', ['$http', 'API',
  function ($http, API) {
    var ApiProjects = {

      getInfo: function (id) {
        return $http.get(API.url + 'project/info?project_id='+ id)
      },
      getAimsList: function (id) {
        return $http.get(API.url + 'project/aims?project_id='+ id)
      }, 
      getAimInfo: function (id) {
        return $http.get(API.url + 'project/aims/'+ id)
      },
    return ApiProjects;
  }]);

And all this is cut in the route resolvers to get data to the controller.
resolve: {
        projectId: ['$stateParams', function($stateParams){
         return $stateParams.id;
        }],
        projectInfo: ['ApiProjects', 'projectId', function(ApiProjects, projectId){
          return ApiProjects.getInfo(projectId);
        }],

And I understand that this is far from the correct option.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nicholas, 2016-09-14
@healqq

make a factory for objects - Projects, your service creates a new object - Project. All operations with an object are performed through the methods of the object.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question