gpt4 book ai didi

angular - 在Angular中显示错误名称(按功能)

转载 作者:行者123 更新时间:2023-12-03 08:46:19 25 4
gpt4 key购买 nike

我试图像这样进入一个文本区域:

  <textarea></textarea>

最佳答案

您只需对html和ts文件进行少量更改。

  1. Change in html


innerHTML不是必需的。如果您具有html内容,则可以改用innerHTML。
<div [hidden]="checkValid()" class="error-message" [innerHTML]="errorMessage">
{{ errorMessage }}
</div>

  1. Change in ts

  errorMessage = ""; <-- You can make it array if you want to store multiple errors.
checkTabsNewLines = ( str ) => {
const reN = /[\n]/mg;
const reT = /[\t]/mg;
if (((str || '').match(reN) || []).length === ((str || '').match(reT) || []).length - 1) {
this.errorMessage = "It has tab lines";
return true;
} else {
return false;
}

}

checkTabsNewLinesSuggestedQ = ( str ) => {

if(true){ . //set the message if function returns true.
this.errorMessage = "checkTabsNewLinesSuggestedQ message"; /<--set message
}

........return false/true}

checkEmptyVal = ( str: string ) => {
if(true){ . //set the message if function returns true.
this.errorMessage = "checkEmptyVal message"; /<--set message
}
....... return false/true
}

关于angular - 在Angular中显示错误名称(按功能),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53056272/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com