Edit/ update :
I forgot my original code in angular 1.6 (normal way) :
http://codepen.io/darkiron/pen/qRJmaj
I think, this can helpe you. My job is convert in EcmaScript ES6.
who work great !
How to use $watch
in ES6 Angular controller ?
loginaction(){
this.$scope.$watch('ui.shake', this.resetUiCheck());
....
}
I try this, the result is not expected
resetUiCheck(newValue, oldValue){
console.log(this.ui.shake);
return () => {
alert('foo');
console.log(this);
if(this.ui.shake == true){
this.$timeout(function(){
this.ui.shake = false;
}, 1000);
}
};
}
return always false!
I try this:
this.$scope.$watch('ui.shake', this.resetUiCheck);
And the result is this error
TypeError: Cannot read property 'ui' of undefined
Another question: the $watch
function should not be set in the Contoller constructor?