Skip to main content

What does the template property do?

The template property in the @Component decorator sets the component's HTML template directly in the code, as a string.

Example:

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

Angular uses this template to render the component's interface, binding it to the class's data and methods.

Unlike templateUrl, where the template is stored in a separate file, template stores it inline directly in the code.

Short Answer

Interview ready
Premium

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