while in console we see that it changed? http://jsfiddle.net/LCZfd/1006/
app.controller("myCtrl", function($document) {
let scope=this;
this.current=0;
this.isCurrent=function(val){
return val==this.current;
}
this.selectCurrent=function(val){
this.current=val;
}
$document.on('keypress', keyupHandler);
function keyupHandler(keyEvent) {
scope.selectCurrent(keyEvent.key-1);
console.log(scope.current);
}
});
Open the console and you will see that variable changed its value. I just want to use keyboard in my app.
return val==this.current;, thethison this context belongs the functionisCurrentnot the controller it self, you may use your cached variablescopelikereturn val == scope.current;instead.thisbut then you don't use it. Try replacing all your references tothiswith the named reference. By the way, 'scope' is not a good idea for the named reference tothisin this context becausethisis actually your controller instance. Name it 'ctrl' or 'myCtrl' or something that won't cause it to be confused with a proper AngularJS scope object.keyEvent.keybut that property is not numeric, so you're assigning NaN to yourcurrentproperty.