Angular 2 Event
Click
This is Example
Template HTML
app.html
<h3>Click Test</h3> <div (click)="clickme()">Click Me!</div> <h3>Click Test2 Event Object</h3> <a (click)="clicked($event)" href="www.google.com">Google</a> <br>
Handle event in Component class
[javascirpt]
import { Component } from ‘@angular/core’;
@Component({
selector: ‘app’,
templateUrl: ‘./app/template/app.html’,
styles: [‘./app/styles/app.css’]
})
export class AppComponent {
private clickme() : void {
alert(“Test!!”);
}
private clicked(event) : void {
event.preventDefault();
}
}
[/javascript]