【问题标题】:How do I interpolate an *ngFor variable inside of a string within a ternary expression? (Angular)如何在三元表达式的字符串内插入 *ngFor 变量? (角度)
【发布时间】:2019-05-28 14:55:53
【问题描述】:

我尝试过的:

  <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!

谢谢

【问题讨论】:

  • 去掉'Sign in with ' + name + 'details!'周围的双引号。
  • 是的,就在我之前到达那里 - 哎呀!谢谢@TimKlein
  • 语法错误不在此处讨论。
  • @Reactgular 我要删除这个问题吗?
  • 这取决于你。您可以改进问题,使其成为主题或等待查看它是否关闭。如果你得到很多反对票,那么我会删除它。

标签: angular interpolation ngfor


【解决方案1】:

就这样试试

  <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>

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

【讨论】:

    猜你喜欢
    • 2019-03-09
    • 2013-01-28
    • 1970-01-01
    • 2022-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-05
    • 1970-01-01
    相关资源
    最近更新 更多