There is no more concept of controller in Angular. Views are now managed by components.
Within template associated with a component, you can leverage its methods and its state. Here is a sample below:
import {Component} from 'angular2/core';
import {CompanyService, Company} from './app.service';
@Component({
selector: 'company-list',
template: `
<h1>Companies</h1>
<ul>
<li *ngFor="#company of companies">
<a href="#" (click)="selectCompany(company)">
{{company.name}}
</a>
</li>
</ul>
`
})
export class ListComponent {
constructor(service:CompanyService,router:Router) {
this.service = service;
this.companies = service.getCompanies();
}
selectCompany(company:Company) {
(...)
return false;
}
}
The click
event is attached to the selectCompany
method using the syntax (click)
.
Hope it helps you,
Thierry