I'm writing an app in Agular2, and some of our components allow for a parent adding style classes. Something like this:
Child component.
@Component({
selector: 'app-label-value',
templateUrl: './label-value.component.html',
styleUrls: ['./label-value.component.css']
})
export class LabelValueComponent implements OnInit {
@Input() label: string;
@Input() value: string;
@Input() valueClass: string;
@Input() labelClass: string;
@Input() cssFile: string;
getLabelClasses(){
let classList = 'label-value-label '
if (this.labelClass){
classList += this.labelClass;
}
return classList;
}
Child Template:
<div [ngClass]="getLabelClasses()">
{{label}}
</div>
Inside parent template.
<app-label-value
[label]="'Just text'"
[value]="'some text'"
[labelClass]="'label-color standard-text'"
[cssFile]="'./app.component.css'">
</app-label-value>
This does not work. The div gets the label-value-label label-color standard-text classes, but they aren't loaded from the ./app.component.css class file (and so not displayed).
The child component needs to somehow find and add the ./app.component.css path to the styleUrls array. Or some other method of telling the component where to look for the class file. But I can't seem to figure out how to do it (or even if it's possible).