-
-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pass attributes to dynamic component #120
Comments
Well unfortunately right now you have to do it yourself imperatively (not via html). And the way you can set attributes is by using Than that can be used along with So here's example: import { DynamicComponent } from 'ng-dynamic-component';
@Component({
selector: 'my-component',
template: `
<ndc-dynamic [ndcDynamicComponent]="dynamicComp"></ndc-dynamic>
`
})
export class MyComponent implements AfterViewInit {
dynamicComp = SomeComponent;
@ViewChild(DynamicComponent) ndcDynamic: DynamicComponent;
constructor(private renderer: Renderer2) {}
ngAfterViewInit() {
const dynamicElementRef = this.ndcDynamic.componentRef.location;
this.renderer.setClass(dynamicElementRef.nativeElement, 'my-class');
}
} NOTE: You have to set your dynamic class only |
I think this is actually a pretty useful thing to be able to set attributes, and it would be really cool to be able to do so declaratively. I have an idea how to make it possible to set via directive but will have do some experiments to validate because it should not be tied to neither That way you can simply apply it on |
Btw for the time being you can create a more usable solution for yourself. You can extend And then when you import |
Thank you sir! |
That is working with ngComponentOutlet directive for right now related #120
Hey @nickbullock, if you want you can try a new directive added in new release that will allow to set attributes right from your templates. Let me know how it works for you =) |
Hi! Thank you for this library.
How can i pass attributes(class for example) to dynamic components?
The text was updated successfully, but these errors were encountered: