Reputation: 768
In Angular 1 we set ng-controller
for any HTML tag in the Razor view and use the functions defined in the angular controller. How I can achieve this view Angular2?
For example I want to click on a HTML tag in Razor View and call a method from an angular2 component or directive.
Any help will be appreciated.
Upvotes: 3
Views: 957
Reputation: 768
What is I searching for ?
Angularjs
functionalities but simpler like
Angular2
.Angular2 unfortunately start the app whit one component and what I want (multi components in on page) not possible.
I would like to experiment Vue
(a framework that bring angular 1 and 2 together).
Upvotes: 0
Reputation: 202346
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
Upvotes: 0