We're currently migrating to Angular 1.3 while testing the bindOnce functionality I encountered this problem: the exact piece of code...
Controller Code:
this.value = 'value';
this.clickTest = function () {
this.value = 'changed';
};
HTML:
//cm is the ControllerAs variable defined in the route
<p> {{ ::cm.value}} </p>
<button ng-click="cm.clickTest()"> CLICK </button>
...works fine in a controller but does not in another one - in the working controller the click event will not change the value, while in the non-working one it will change the value - (the code is exactly the same in both controllers, routing changes and apparently something else changes too). Both controllers were emptied in order to have a better testing environment.
Now what I'd like to know is: is there something that can prevent the bindOnce functionality to work as expected? Is there something that force angular code to not delete the watcher or to enable it again despite the correct syntax (::) has been used in the view?
I am working with Angular 1.3.2
I think the value not changing after the click, bcoz of the context of
this
is changed for theclickTest
functionTry the code below, hope it works
And for the bindOnce, I don't think its possible to bind again after the value is changed in the controller, and for testing the code, we should not worry about the view.