I have 2 controllers using the same service, the first controller change the value of a property on the service, I need the second controller to know the property has changed to set the new value in his current $scope. I dont want to use broadcast, is there an elegant way to do this ?
Thank you.
You could create an
object
in angular service,that will have various shareable properties in it. You could directly assign that variable with your controller scope variable. So that the reference of variable use by both controller are the same, like we gave tomyCtrl1
andmyCtrl2
will have only one copy in there scope variable. So changes in one variable updates the other one.Markup
Controller1
Controller2
Demo Plunkr
This will be fired once your value change and you can propagate it to new controller