When setting up TypeScript in an Angular project, I use the following syntax to declare a controller:
module app {
class MyController {
public myvar: boolean;
constructor() {
this.myvar= false;
}
}
angular.module("app").controller("MainController", [MainController]);
}
It's important to note that I prefer not to inject the scope and instead utilize inner properties/methods of the controller. However, I find accessing properties with 'this' to be cumbersome. Typically, I would have to declare:
var vm = this.
vm.myvar = ...
This becomes repetitive as I have many methods; each one requiring the 'vm' declaration. Are there any best practices or patterns for declaring 'vm' only once?