There is no controllerAs equivalent in Angular 2. For example, given this class and the controller pattern:
@Component({ selector: 'component-a', template: `<div class="component-a"> <div class="counter" (click)="increment()">Component A: {{counter}}</div> </div>` }) export class ComponentA { counter = 0; increment() { this.counter += 1; } }
In the increment() method, this limited to the controller instance of this component itself. In the template, access to the counter can be obtained through {{counter}} .
As we can see, there is no mechanism for specifying the controller, because we can already access it using the default functionality.
You might think that the controllerAs mechanism was integrated into the functionality of the default Angular 2 component or this function was removed as it is no longer needed, depending on how you look at it.
source share