AngularJS $watch for value changes after initialization

angularjs, angularjs-directive, javascript

Solution

I solved it finally!

Plunker: http://plnkr.co/edit/a5fzJi7VzAytj3Urj06L?p=preview

The `form` directive in Angular has a property called `$dirty`. It starts as false and when you change the value of an input, the `ngModel` directive makes the form "dirty". First I tried to use `ngModel` in my directives but I ended up requiring using the `form` directly.

PS. This is triggered only on the first change, but this is exactly what I needed.

Problem

I have this situation where I need to capture the event when a model is changed but the initialization in my directive triggers the event too early. Plunker: http://plnkr.co/edit/2T0Rq6yOXHWxQAOv8RpX?p=preview How can I overcome this? Setting some flags, but how/where? Other approaches? Thanks! UPDATE I added the `value` attribute to the directive so you can understand better what I mean by initialization. Plunker: http://plnkr.co/edit/a5fzJi7VzAytj3Urj06L?p=preview

Original source