AngularJS : The correct way of binding to a service properties

前端 未结 10 1834
天命终不由人
天命终不由人 2020-11-28 00:30

I’m looking for the best practice of how to bind to a service property in AngularJS.

I have worked through multiple examples to understand how to bind to properties

10条回答
  •  庸人自扰
    2020-11-28 00:57

    To bind any data,which sends service is not a good idea (architecture),but if you need it anymore I suggest you 2 ways to do that

    1) you can get the data not inside you service.You can get data inside your controller/directive and you will not have a problem to bind it anywhere

    2) you can use angularjs events.Whenever you want,you can send a signal(from $rootScope) and catch it wherever you want.You can even send a data on that eventName.

    Maybe this can help you. If you need more with examples,here is the link

    http://www.w3docs.com/snippets/angularjs/bind-value-between-service-and-controller-directive.html

提交回复
热议问题