Brief Explanation: Due to some requirement, HTML
code is written in home.ts
and is loaded on home.html
. CSS
style is written in home.ts
style component.
Problem: CSS
style is not getting effected in the HTML
code.
home.ts code:
@Component({
selector: 'page-home',
templateUrl: 'home.html',
styles:[`.p-tag{font-size:20px; color:red;}`]
})
export class HomePage {
code2='';
constructor(public navCtrl: NavController, private formBuilder: FormBuilder) {
}
ionViewDidEnter()
{
// css .p-tag style is not effecting in below line on html page
this.code2 = '<p class="p-tag">Html code From ts file.</p>';
}
}
home.html code:
<ion-content>
<div [innerHtml]="code2 | noSanitize"></div>
</ion-content>
For some reason we cannot call css
from .scss
file. We need to keep both css
and html
in ts as shown in above code.