Issue: In angular2, note.component.css file doesn't work for dynamically created element within note.component.ts. Does anyone know the reason? Or is it the correct behaviour?
note.component.css can work for element already existed in note.component.html. If I put the css style in file "styles.css", it worked. If I set the style with DOM, it worked.
File structure:
app
components
note
note.component.css
note.component.html
note.component.ts
index.html
styles.css
note.component.html:
<div id="section1"></div>
note.component.css:
button{
background-color: green; //doesn't work
}
styles.css:
button{
background-color: green; //worked
}
note.component.ts:
ngOnInit() {
var div = document.createElement("button");
div.innerHTML = "Hello world";
// div.style.backgroundColor = "green"; --- worked
document.getElementById("section1").appendChild(div);
}