簡體   English   中英

ngModel innerHTML在p標簽中工作,但在輸入標簽angular2中不起作用

[英]ngModel innerHTML works in p tag but not in input tag angular2

在我的一個angular2應用程序中,我想在輸入字段中顯示模型的innerHTML,其中附有一個模型。

<input type="text"  [(ngModel)]="studentCategory" [innerHTML]="studentCategory"/>

studentCategory的值來自數據庫,其中有一些'&#174;' 值。 它直接顯示在文本框中,而應顯示寄存器符號

我可以通過以下方式輕松展示這一點

<p [innerHTML]="studentCategory"/></p>

但不是在有模型附加的輸入中。

提前致謝。

innerHTML指的是HTML標記的內容。

<p>標簽可能包含措辭內容。 但是, <input>標記必須為空。 它可能沒有任何子元素也沒有文本內容。

<p [innerHTML]="'hello'"></p>解析為<p>hello</p> 這是合法的HTML。 <input>hello</input>無效。 <textarea>hello</textarea>有效)。

在將字符串分配給ngModel變量studentCategory之前,您需要確保HTML實體已經未轉義。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM