Hi Mustapha, thanks for the article. Just wondering why you didn't use @ContentChild instead of using the @Input?
eg. @ContentChild(TemplateRef, {static: false}) public itemTemplate:TemplateRef;
This would save you importing & declaring the Input
It would save you adding [itemTemplate]="customItemTemplate" in the parent.
It would save adding the template reference variable #customItemTemplate in the parent.
I feel it's cleaner and would be easier to maintain, BUT I am only a junior developer so I look forward to your reply. Have a great day...
Both ways are absolutely valid and thereβs not a better way to do it as both methods have their pros and cons. Also I disagree on the maintainability, if not I find using @input way more maintainable on large projects.
If you are building components for your own usage you can use contentChild as you mentioned. If you are building components for other people (other teams At your company for example), using input is more explicit and more flexible (the templateRef doesnβt have to be in the projection area for example).
For instance ng-zorro (ant design library) use this approach.
At the end of the day, it depends on what you want to achieve, one method is more declarative, the other is more imperative.
Hi Mustapha, thanks for the article. Just wondering why you didn't use @ContentChild instead of using the @Input?
eg. @ContentChild(TemplateRef, {static: false}) public itemTemplate:TemplateRef;
Hi David,
Both ways are absolutely valid and thereβs not a better way to do it as both methods have their pros and cons. Also I disagree on the maintainability, if not I find using @input way more maintainable on large projects.
If you are building components for your own usage you can use contentChild as you mentioned. If you are building components for other people (other teams At your company for example), using input is more explicit and more flexible (the templateRef doesnβt have to be in the projection area for example).
For instance ng-zorro (ant design library) use this approach.
At the end of the day, it depends on what you want to achieve, one method is more declarative, the other is more imperative.
Thank you so much for the reply and sharing your knowledge. I've been using your guitar app as well, it's awesome!!!