Angular use root scope vs services to share data

前端 未结 3 2175
清歌不尽
清歌不尽 2020-12-09 23:32

I have been reading wrox angular book. Inside the book the author describes that a method of sharing data between controllers is to

  1. Have a property on the roo
3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-09 23:50

    It depends which kind of data you are managing, if you are for example relying on a DB where you perform CRUD actions, you'd like a service to just interact with the DB.

    That's called a stateless service, some people vouch for it and some are against and prefer to have state also on the service, exposing the object as you mentioned.

    I'll leave you a couple resources with more information on the topic so you can decide which solution suits you best

    http://www.johnpapa.net/sharing-data-in-an-angular-controller-or-an-angular-service/

    http://www.webdeveasy.com/angularjs-data-model/

提交回复
热议问题