是否可以替换 html 代码中的文本
Is that possible to replace text from html code
我有变量label1= "please pay $ 50:#000000"
是否可以从 html code
替换 :#000000
和设置颜色 :#000000
现在我的html代码是这样的
<labe>{{label1}}</label>
但我需要让它像:
if(label1 contains :#000000
or :DC143C
then replace it with empty string("")
and set font color as color available in variable label1
是的。您可以通过 :
split
变量 label1
试试这个:
TS:
GetValue(str: string, type:string) {
var splitArray: string[] = str.split(":");
if(type == "text") {
return splitArray[0];
} else {
return splitArray[1];
}
}
HTML:
<label [style.color]="GetValue(label1,'color')">
<span [innerHtml]="GetValue(label1,'text')">
</span>
</label>
是的,您可以直接在 html 中拆分文本..
Html:
<label [ngStyle]="{ 'color': label1.split(':')[1]}">{{label1.split(':')[0]}} </label>
无需在打字稿中编写额外的代码。
编码愉快。
我有变量label1= "please pay $ 50:#000000"
是否可以从 html code
:#000000
和设置颜色 :#000000
现在我的html代码是这样的
<labe>{{label1}}</label>
但我需要让它像:
if(label1 contains :#000000
or :DC143C
then replace it with empty string("")
and set font color as color available in variable label1
是的。您可以通过 :
split
变量 label1
试试这个:
TS:
GetValue(str: string, type:string) {
var splitArray: string[] = str.split(":");
if(type == "text") {
return splitArray[0];
} else {
return splitArray[1];
}
}
HTML:
<label [style.color]="GetValue(label1,'color')">
<span [innerHtml]="GetValue(label1,'text')">
</span>
</label>
是的,您可以直接在 html 中拆分文本..
Html:
<label [ngStyle]="{ 'color': label1.split(':')[1]}">{{label1.split(':')[0]}} </label>
无需在打字稿中编写额外的代码。 编码愉快。