Replace HTML tag with text Angular 6

Multi tool use
Multi tool use


Replace HTML tag with text Angular 6



I want to change a specific word in my code with HTML tag and change style of my text with themecolor class.


<h2 class="mb-30" [innerHTML]="main_title"></h2>



Preview of result:



This is text.



I want to replace <span class="themecolor">text</span> with text.


<span class="themecolor">text</span>


text



I built my application with Angular 6




2 Answers
2



Not sure why you need such functionality since Angular is component based where you have html injected via selectors.



Anyway,
stackblitz



The bindind occures as you wanted in this line:


<h2 class="mb-30" [innerHTML]="main_title"></h2>



All I do is instantiating main_title with custom HTML of your choice in app.component.ts



Also, please note that I used ngDoCheck in order to detect changes on the text input.



This will allow you to enter HTML inside the textbox (preferred as textarea actually).





i want to change stye of my text with css. this is not my answer @monogate
– Mohammad Jalili
Jun 30 at 8:33



property: string = "Text";

Use [innerText]="property"
<p [innerText]="property/variable"></p>



This will insert the text into your html






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

CtfjdV RAvAilx0NBZ,Ml7 t a
QLPGNTF5NMn4ynpZchto 78BXxF,mPt EKD,KwAHUDzn

Popular posts from this blog

Delphi Android file open failure with API 26

.

Amasya