I use the 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."); } }
:
<input type="text" data-ng-model="vm.txt" data-ng-change="vm.textTyped()"/>
So, "Hello" from within the constructor gets the record in order. But the "change" in the typedText () function does not work, because, apparently, it is undefined, how to make my textTyped () class function access the $ log service?
Note If I assign $ log to the class property in the constructor, for example,
this.logger = $log;
And then do
this.logger.debug("Change fired.");
it works. But I'm not sure if this is the right approach.
Refresh . In addition, this approach provides this link to the $ log service for the view associated with this controller. It's unhealthy?
Is there a better solution?
source share