I am using ES6 class to define my controller so this is the syntax,
export class SearchBarController {
constructor($log) {
'ngInject';
$log.debug("Hello");
}
textTyped($log){
$log.debug("change fired.");
}
}
view :
<input type="text" data-ng-model="vm.txt" data-ng-change="vm.textTyped()"/>
So "Hello" from within the constructor is getting logged fine. But, "change fired" within the typedText() function is not firing because apparently is undefined how do I make my class function textTyped() to access the $log service?
Note : If I assign $log to a class property in the constructor like,
this.logger = $log;
And then do,
this.logger.debug("Change fired.");
this works. But I am unsure if it's the right approach.
Update: Also, this approach exposes this reference to the $log service to the view bound to this controller. Is this harmful?
Is there a better solution?
this.logger = $logis the recommended approach.