app.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
randomNumberInt:number = -1;
randomNumberFloating:number = -1;
generateRandomNumberInt(){
// Generate random integer from 0 to 9
this.randomNumberInt = Math.floor(Math.random()*10);
}
generateRandomNumberFloating(){
// Random number between 0 (inclusive), and 1 (exclusive)
this.randomNumberFloating = Math.random();
}
}
app.component.html
<h2>Angular - Generate Random Number</h2>
<ng-template [ngIf]="randomNumberInt>=0">
Random Number Int: {{randomNumberInt}}
</ng-template>
<br/>
<button (click)="generateRandomNumberInt()" style="padding:12px;">
Get Random Number Int
</button>
<br/><br/>
<ng-template [ngIf]="randomNumberFloating>=0">
Random Number Floating: {{randomNumberFloating}}
</ng-template>
<br/>
<button (click)="generateRandomNumberFloating()" style="padding:12px;">
Get Random Number Floating
</button>
- angular - How to use ternary operator
- angular - Generate random number in range
- angular - Generate random whole number
- angular - How to submit form data
- angular bootstrap - Dismissible alert
- angular bootstrap - Danger warning success alert
- angular bootstrap - Alert closed event
- angular bootstrap - Rating hover event
- angular bootstrap - Readonly & editable Rating
- angular bootstrap - How to show Toast message
- angular bootstrap - Popover manual triggers
- angular bootstrap - Popover custom CSS class
- angular bootstrap - Popover shown & hidden event
- angular bootstrap - Datepicker navigate to specific year month
- angular bootstrap - Datepicker navigate select specific date