Separate controller models

I have something like this -

function DetailCtrl($scope) { $scope.persons = [{ id: 1, name: "Mark" }]; } 

I would like to leave the models separate from the controller, for example:

  //models var person = { id: '', name: '' }; function DetailCtrl($scope) { person = db.getPerson(); $scope.person = person; } 

Is this good practice in angularjs? I came from ASP.NET MVC background.

+4
source share
1 answer

Yes, it’s best to use your models in other places, and your applications refer to your models: listen to Mishko for 2 minutes from his video "Best Practices".

Services are a good place to store your models.
Brandon has a good answer related to this: fooobar.com/questions/17863 / ...

+3
source

Source: https://habr.com/ru/post/1479937/


All Articles