[英]ngModel innerHTML works in p tag but not in input tag angular2
In one of my angular2 application, I want to show the innerHTML of the model in the input field which has a model is attached to it. 在我的一个angular2应用程序中,我想在输入字段中显示模型的innerHTML,其中附有一个模型。
<input type="text" [(ngModel)]="studentCategory" [innerHTML]="studentCategory"/>
the value of studentCategory is coming from data base which has some '& #174;' studentCategory的值来自数据库,其中有一些'&#174;' values.
值。 which is directly showing up in the text boxes, rather it should show a register symbol
它直接显示在文本框中,而应显示寄存器符号
i can easily show this in the following way 我可以通过以下方式轻松展示这一点
<p [innerHTML]="studentCategory"/></p>
but not in input which has model attach to it. 但不是在有模型附加的输入中。
Thanks in advance. 提前致谢。
innerHTML
refers to the content of the HTML tags. innerHTML
指的是HTML标记的内容。
A <p> tag may contain phrasing content. <p>标签可能包含措辞内容。 An <input> tag, however, must be empty.
但是, <input>标记必须为空。 It may not have any child elements nor text content.
它可能没有任何子元素也没有文本内容。
<p [innerHTML]="'hello'"></p>
resolves to <p>hello</p>
. <p [innerHTML]="'hello'"></p>
解析为<p>hello</p>
。 This is legal HTML. 这是合法的HTML。 But
<input>hello</input>
is not valid. 但
<input>hello</input>
无效。 ( <textarea>hello</textarea>
would be valid). (
<textarea>hello</textarea>
有效)。
You need to ensure that the HTML-entities are already unescaped before you assign the string to your ngModel variable studentCategory. 在将字符串分配给ngModel变量studentCategory之前,您需要确保HTML实体已经未转义。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.