Skip to main content

angular - How to use Button click event

app.component.ts

import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})

export class AppComponent {
  counter:number = 0;
  countUp(){
    this.counter++;
  }
}
app.component.html

<h2>Angular Button Click Event</h2>

<button (click)="countUp()" style="padding:12px;">
    Count Up
</button>

<h3>{{counter}}</h3>
More Angular tutorials