Inline Components - Inline Template & Styles
Inline Component in Angular
An inline component is a component where HTML and CSS are written inside the same TypeScript file. Everything stays in one file.
Why Inline Components Are Used
Inline components are used when the component is very small, like an input box, button, or simple UI part.
Creating many files for small work is not needed, so one file is enough.
Inline Component Example
In SearchBox component, the HTML is written using template and CSS is written using styles.
This is called an inline component because template and style are inside the TS file.
Using Inline Component
The component is used with its selector like an HTML tag.
Using Inline Component Inside Loop
Inline components can be used inside a loop.
The new control flow @for is used.
This creates multiple search boxes.
Inline Template or Inline Style
If inline-template is used, HTML stays inside TS file and CSS goes outside.
If inline-style is used, CSS stays inside TS file and HTML goes outside.
Important Interview Meaning
Inline components keep code in one file.
They are good for small components.
Components can be used inside loops.
Use @for, not *ngFor.