小编ran*_*unj的帖子

在ionic 3和Angular 4中使用的文本中的随机颜色生成器

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)

text colors ionic-framework ionic3 angular

0
推荐指数
1
解决办法
1101
查看次数

标签 统计

angular ×1

colors ×1

ionic-framework ×1

ionic3 ×1

text ×1