我正试图显示内联错误信息。
我的目标是实现这个目标。
错误1
错误2
但它却出现在同一行中,如 。错误1 错误2
我试着用document.createElement("br"),但没有用。
以下是我的代码。
HTML:
<span *ngIf="ifError()"class="validation_class">
<p id="inline_error">{{inlineErrorMsgs}}</p></span>
TS:
ifError(){
var Errormsg:string;
var br = document.createElement("br");
for(var i=0;i<this.messages.length;i++){
Errormsg = this.messages[i]
this.inlineErrorMsgs = this.inlineErrorMsgs+Errormsg+br;
}
我如何添加新行
HTML
<div *ngIf="errorMessages && errorMessages.length > 0">
<div *ngFor="let d of errorMessages">
<p>
{{d}}
</p>
</div>
</div>
TS
export class ComponentA {
errorMessages : [] = [];
someMethod(){
this.messages.forEach((j) => {
// here you can add some logic if you want.
errorMessages.push(j);
})
}
请不要直接使用文档对象,或者说尽量避免使用。
将错误信息存储在数组中,然后使用ng-for循环显示。