如何轻松地将 typescript 变量与 html 标记中的字符串连接起来? [英] How can I easily concatenate typescript variable with string in html tag?

查看:17
本文介绍了如何轻松地将 typescript 变量与 html 标记中的字符串连接起来?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的 ionic 2 html 代码

This is my html code with ionic 2

<ion-item *ngFor="let job of allFreeJobs;let elementid=index">
     <p>
        <span id="m{{elementid}}" (click)="showMore(elementid)" color="primaryAdmin">...<ion-icon name="bicycle"></ion-icon></span>
      </p>
</ion-item>

从上面的代码来看,这是我关注的领域:

From the code above this is my area of concentration:

... id="m{{elementid}}" ...

如何轻松地将 m 与变量 elementid 连接起来?这对我不起作用.

How can I easily concatenate m with the variable elementid? This is not working for me.

推荐答案

Angular 文档,你可以使用插值:

As explained in Angular documentation, you can use interpolation:

id="{{'m' + elementid}}"

或属性绑定:

[id]="'m' + elementid"

这篇关于如何轻松地将 typescript 变量与 html 标记中的字符串连接起来?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆