Fractaliste Fractaliste -3 years ago 91
AngularJS Question

How to execute a function when a value change?

I've a main controller and into it two other controllers:

<div ng-controller="mainController" ng-model="value">
<div ng-controller="otherController"></diV>
<div ng-controller="anOtherController"></div>

Thanks to the controller inheritance my
can update my
I bind with the

But how can I notice my
that the
have changed in order to execute a function owned by anOtherController?

Can I register a function to this value?

Answer Source

You can do this in your controller..

 // your code goes here...

It will basically watch for any changes on a given "scope property". However, my advice is to use a either a service or a factory.

Please refer to this other SO Discussion:

AngularJS Service Passing Data Between Controllers

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download