Reputation: 586
I'm trying to set styles to dynamically created components.
I want to do something like this, because what i want can't be done with s/css styles (class or id).
<div [style.height]="myVar">
The components that i'm creating are:
let widgetResourceGroupFactory = this.resolver.resolveComponentFactory(ResourceGroupComponent);
for (let group of this.groups) {
let widgetResourceGroupReference = this.content.createComponent(widgetResourceGroupFactory);
widgetResourceGroupReference.instance['group'] = group;
widgetResourceGroupReference.instance['slug'] = group.slug;
this.renderer.listen(widgetResourceGroupReference.location.nativeElement, 'click', () => {
this.loadCategories(group);
});
}
I want to set a custom style to widgetResourceGroupReference
, but what i was trying didn't work, that was a sort of instance['style.height']
.
Thanks u very much.
Upvotes: 1
Views: 544
Reputation: 586
Well, i solved it with renderer:
this.renderer.setElementStyle(widgetResourceGroupReference.location.nativeElement, 'width', this.upperLeftWidth);
Upvotes: 2