Modify a components template prior to compilation in Angular 8

18 views
Skip to first unread message

Damo

unread,
Jul 25, 2019, 1:42:02 AM7/25/19
to Angular and AngularJS discussion
Hi,

I have been trying various ways to reorder, hide or add/remove extra validation of form fields dynamically based on a configuration json.

Use Case: Customer has specific business rules that must be applied to a screen dynamically

When I try to do this in Angular 8 the only way I have found that works is by storing the component template in a string (This is not ideal since making a component as a string is a mess) 

I then manipulate the template string using DOMParser prior to generating the component using compileModuleAndAllComponentsSync function.

Is there any way that this can be achieved without using a string?

In Angular 1 we were able to modify the template string in the compile function but this is no longer possible.

I have been looking at the code for Dialog.open (https://github.com/angular/components/blob/master/src/material/dialog/dialog.ts#L128) but I do not see how I can manipulate the template prior to injection.

Any help with this is much appreciated

Thanks
Damien

Séanadh Ríomhphoist/

Email Disclaimer

Tá an ríomhphost seo agus aon chomhad a sheoltar leis faoi rún agus is lena úsáid ag an seolaí agus sin amháin é. Is féidir tuilleadh a léamh anseo. 

This e-mail and any files transmitted with it are confidential and are intended solely for use by the addressee. Read more here. 

Sander Elias

unread,
Jul 25, 2019, 11:56:26 AM7/25/19
to Angular and AngularJS discussion
Hi Damo,

I think that for this use-case AngularElements is the best way forward.

Regards
Sander

Damo

unread,
Jul 29, 2019, 10:43:42 AM7/29/19
to Angular and AngularJS discussion
Hi Sander,

Thanks for the suggestion. Can you help me understand how I would be able to modify the CustomComponent at runtime when using AngularElements?

My main issue is not being able to manipulate the template before it gets compiled.

Not sure how AngularElements resolves this issue.

Thanks
Damien

Damo

unread,
Jul 30, 2019, 2:59:09 PM7/30/19
to Angular and AngularJS discussion
FYI I was able to resolve the template as string issue by requesting the template via http

Thanks for your help
Reply all
Reply to author
Forward
0 new messages