app.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
randomNumber:number = -1;
getRandomNumber(max:number){
this.randomNumber = Math.floor(Math.random() * max);
}
}
app.component.html
<h2>Angular - Call Function On Button Click</h2>
<button (click)="getRandomNumber(100)" style="padding:12px;">
Get Random Number
</button>
<h3 *ngIf="randomNumber>=0">
{{randomNumber}}
</h3>


- angular - How to use Button click event
- angular - Text input on change listener
- angular - How to get text input value
- angular - How to create a counter
- angular bootstrap - Rating hover event
- angular bootstrap - Readonly & editable Rating
- angular bootstrap - How to show Toast message
- angular bootstrap - How to use Popover
- angular bootstrap - Open Popover on mouse hover
- angular bootstrap - Open close Popover on button click
- angular bootstrap - Popover manual triggers
- angular bootstrap - Popover custom CSS class
- angular bootstrap - Popover shown & hidden event
- angular bootstrap - Timepicker without spinner
- angular bootstrap - Timepicker custom steps