Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Math function not working in angular 4 HTML

Using the following line :

<div class="card light-blue darken-4" [ngClass]="'card-grad-'+Math.floor(Math.random() * 10) + 1">

gives the following error:

ERROR TypeError: Cannot read property 'floor' of undefined

and component.ts.

How to resolve it ?

Even tried using decare var Math:any and also tried defining Math in the class but in vain.

like image 247
Shakti Phartiyal Avatar asked May 11 '26 10:05

Shakti Phartiyal


1 Answers

Declare the Math in your component.ts

Math = Math;

or create a function that would calculate your value and bind that to ng-class

like image 69
Sajeetharan Avatar answered May 12 '26 23:05

Sajeetharan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!