首页 > 解决方案 > 如何在三元表达式的字符串内插入 *ngFor 变量?(角度)

问题描述

我试过的:

  <mat-step *ngFor="let name of names" [label]="name" [completed]="name + 'IsCompleted'">
    <button mat-button (click)="redirectToNameUrl(name)" mat-raised-button color="primary">
  {{ (inProgress ? 'In progress...' : "'Sign in with ' + name + 'details!'" )}}
    </button>
  </mat-step>

注意:嵌套车把似乎也不起作用。

结果:

一个按钮,上面写着'Sign in with ' + name + 'details!'

我希望它会说:

Sign in with james details!

谢谢

标签: angularinterpolationngfor

解决方案


试试这样

  <mat-step *ngFor="let name of names" [label]="name" [completed]="name + 'IsCompleted'">
    <button mat-button (click)="redirectToNameUrl(name)" mat-raised-button color="primary">
  {{ (inProgress ? 'In progress...' : 'Sign in with ' + name + 'details!' )}}
    </button>
  </mat-step>

您不需要文本周围的额外双引号


推荐阅读