home.html
创建卡并访问json以获取值和数据
<ion-card *ngFor="let shayari of shayar_list">
<div class="card-title" [ngStyle]="{'color':shayari.color{{shayari.title}}</div>
</ion-card>
Run Code Online (Sandbox Code Playgroud)
.ts
创建一个json并访问math.random函数调用
this.shayar_list = [{
title: 'Love Shayari',
color : this.getRandomColor(),
]}
Run Code Online (Sandbox Code Playgroud)
创建一个随机的颜色生成器功能
getRandomColor()
{
var color = "#";
for (var i = 0; i < 3; i++)
{
var part = Math.round(Math.random() * 255).toString(16);
color += (part.length > 1) ? part : "0" + part;
}
return color;
}
Run Code Online (Sandbox Code Playgroud)