![]() ![]() What you want to do instead is allow for an external template to plug into the component using either templateref or ng-content (check my plugin architecture post for an example of this with ng-content). This gets very painful as the amount of input keeps growing, as well as the complexity of the reusable component as it should handle more edge cases, in the end making the component harder to reuse than if it were simply copied and modified to serve the purpose. I have seen cases here where this has escalated to creating a dedicated DSL for rendering components. For example, you might need a fieldsDefinitions and actionDefinitions input for determining the fields and different actions in a list and inside the reusable component, you then need to have a lot of logic to render the input data. On the other hand, this becomes a pain when you need to pass lots of inputs to the component to provide the necessary data to the component. An example of this is a simple questionnaire that should be dynamically rendered using json data from an API. If you have a simple reusable component that doesn’t need to be very flexible, simply using inputs will do. ![]() The choice of which technique to reuse components you should use is determined by the desired flexibility.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |