Binding variables from Service/Factory to Controllers

前端 未结 2 1059
抹茶落季
抹茶落季 2020-11-29 18:26

I have a variable that will be used by one or more Controllers, changed by Services. In that case, I\'ve built a service that keeps this variable in memory, and share betwee

2条回答
  •  暖寄归人
    2020-11-29 19:11

    It's not good idea to bind any data from service,but if you need it anymore,I suggest you those following 2 ways.

    1) Get that data not inside your service.Get Data inside you controller and you will not have any problem to bind it.

    2) You can use AngularJs Events feature.You can even send data to through that event.

    If you need more with examples here is the article which maybe can help you.

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

提交回复
热议问题