ng-repeat with multiple filters on large data set

前端 未结 5 1528
無奈伤痛
無奈伤痛 2020-12-13 12:49

I\'m still new to AngularJS, so I\'m just trying to do a simple CRUD app. Currently I pull the data (in a JSON file) with $http in a div handled by

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-13 13:23

    CRUD should be handled in a factory or service, not in the controller. My understanding is that a controller is only responsible for communication between the views and services.

    Edit 1: excerpt from John Papa Style Guide (Angular -1) - Defer logic in a controller by delegating to services and factories.

    Why?: Logic may be reused by multiple controllers when placed within a service and exposed via a function.

    Why?: Logic in a service can more easily be isolated in a unit test, while the calling logic in the controller can be easily mocked.

    Why?: Removes dependencies and hides implementation details from the controller.

    Why?: Keeps the controller slim, trim, and focused.

    https://github.com/johnpapa/angular-styleguide/blob/master/a1/README.md#style-y035

提交回复
热议问题