【发布时间】:2020-06-16 10:20:33
【问题描述】:
我想在电子邮件无效时以红色显示数据。
我没有。的数据,其中一些电子邮件 ID 未经过验证。 我只使用了动态类。
//ts file
email_regx = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
if (this.data.email_id) {
this.email_regx = true;
} else {
this.email_regx = false;
}
//html file
<span [ngClass]="{'redClass': email_regx}">{{ data?.email_id }}</span>
//css
.redClass{ color: red}
【问题讨论】:
-
<input type="email" />会所以容易得多... -
不,我只想要 ngclass
-
你为什么要这么做
this.email_regx = true;。你应该做这样的事情。this.data.email_id.test(this. email_regx)
标签: javascript regex angular typescript