Skip to main content

What does the selector property do in the @Component decorator?

The selector property in the @Component decorator sets the HTML tag name through which the component can be inserted into the templates of other components.

Example:

typescript
@Component({ selector: 'app-my-component', template: `<p>Hello!</p>` }) export class MyComponent {}

Now it can be used in any template:

html
<app-my-component></app-my-component>

Angular recognizes this tag and inserts the component's template and logic inside it.

Conclusion: selector is the component's entry point into the DOM.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.