Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
69
rated 0 times [  74] [ 5]  / answers: 1 / hits: 17798  / 6 Years ago, sun, september 30, 2018, 12:00:00

How can I bind input texts to span innerHTML in Angular6?



ts file



...
finance_fullname: string;
...


template file



<input type=text id=finance_fullname [(ngModel)]=finance_fullname>
<span class=fullname ngBind=finance_fullname></span>

More From » angular

 Answers
26

I can say most secure way would be innerText or textContent.



<span class=fullname [textContent]=finance_fullname></span>
<span class=fullname [innerText]=finance_fullname></span>


Even AngularJS were using textContent for one way binding. It only extract the model value and dump directly inside the specified html node. Even though if you pass html it will add that html as a text(decoded html) on the page.



Demo



innerHTML would also work for you, but it could be dangerous, as it will give a chance to inject malicious content on the page in form of html.


[#53399] Tuesday, September 25, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
draven

Total Points: 641
Total Questions: 101
Total Answers: 110

Location: Nicaragua
Member since Mon, Sep 26, 2022
2 Years ago
;