文本区域中的Angular 2多种字体颜色 [英] Angular 2 multiple font colors in a textarea
问题描述
我有一个文本区域,上面绑定了一个字符串.文字颜色默认为白色.
绑定字符串包含多个变量.
return this.outputText = this.test1 + " test1Stat" + this.test2 + " test2Stat" + this.test3 + " test3Stat";
我想要做的是,如果 test1 小于 1,它应该以红色显示test1 test1Stat",而其他所有内容都以绿色显示.有没有办法做到这一点?
无法为 textarea 中的部分文本着色,但是,您可以尝试改用contenteditable"属性.
它基本上把你的 div 变成了一个文本框,你可以在里面使用 html 标签等.
.greenText{颜色:绿色;}div{边框:黑色实心1px;填充:20px;}
<div contenteditable="true">text text <span class='greenText'>GREEN TEXT</span>您可以编辑的更多文本
I have a text area with one string binded to it. With the text color as white by default.
<textarea style="background-color: black;color:#fff;" [(ngModel)]="outputText"></textarea>
The bound string contains multiple variables.
return this.outputText = this.test1 + " test1Stat" + this.test2 + " test2Stat" + this.test3 + " test3Stat";
What I want to do is, if test1 is less than 1, it should show "test1 test1Stat" in red, while everything else is in green. Is there a way to do this?
It's not possible to color part of the text in a textarea, However- you can try to use the 'contenteditable' property instead.
It basically turns your div into a textbox, and you can use html tags and such inside.
.greenText{
color:green;}
div{
border:black solid 1px;
padding:20px;
}
<div contenteditable="true">text text <span class='greenText'>GREEN TEXT</span> more text that you can edit</div>
这篇关于文本区域中的Angular 2多种字体颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!