Implementing shared logic for CRUD UI Components in Angular

1 Like

Hi Tobias,

Thanks for sharing your approach with us.

I’m curious why you didn’t use NgComponentOutlet or dynamic rendering rather than NgSwitchCase.

Hi Lars,

Thanks for your comment.

We have chosen NgSwitch because it seemed simple and straightforward. However, it is clearly repetitive and not very elegant.

We will thus consider using the approaches you suggested (I have just created a task for this and assigned it to me :-)). We will have to make sure though that value components can still receive specific inputs (inputs that are not defined in the base class, but just in one specific component).

I have used the component portal once (https://github.com/angular/components/pull/9639) but the component that you could pass in did not require any further configuration.

1 Like

I see. Andrew Grekov aka thekiba aka Reactive Fox made the library NGXD which does what you’re asking for:

As its readme says, you can do the same thing with ComponentFactoryResolver and a ViewContainerRef, but you have to do bindings and some wiring manually. This is what I meant by dynamic rendering (that or renderComponent).

NgComponentOutlet allows content projection and injector inheritance, but doesn’t allow binding.

1 Like

Thanks for the reference to https://github.com/IndigoSoft/ngxd!

Do you happen to know if this will be integrated into Angular some day?

I’ll get the NGXD author in here to join the discussion.

1 Like