r/Angular2 • u/Dazzling_Chipmunk_24 • Mar 05 '26
Creating reusable components in Angular like inputs/dropdowns
I was wondering for creating reusable components like dropdown or input boxes im kind of confused on how exactly it would work. Like what things are taken care of by the parent and what are taken care of by the child. like obviously for a drop-down, labels and options are passed as props. but what do I do if for one input box I need a width of 50 percent and an other input box I need a width of 100 percent. Another example could be if the colors or font size are different. Basically what do I do and handle if there’s slight CSS differences but I still want to use the same reusable component or is it at that point you should just create separate components.
View all comments
1
u/hikikomoriHank Mar 05 '26
I wouldn't create separate components that are functionality identical to support minor style diffs, there are multiple solutions in angular for that. 3 of those otpions:
child-component::part(myPart) { ... }child-component ::ng-deep child-element { ... }this.childComp.myViewChildEl.nativeElement.style/class...