Sitemap
Pravin M

Pravin M

I am a frontend developer with 10+ years of experience Blog :- https://www.frontendinterviewquestions.com

Member-only story

Declarations in Angular

3 min readJul 20, 2024
Press enter or click to view image in full size
Declarations in Angular

For more questions and answers visit our website at Frontend Interview Questions

Declarations in Angular refer to the process of registering components, directives, and pipes within a module so that Angular knows how to instantiate and use them. They essentially declare the building blocks of your Angular application, making them available for use in templates and other components.

Types of Declarations

  1. Components: Components are the cornerstone of Angular applications. They are typically defined using the @Component decorator and consist of a TypeScript class and an HTML template.
// Example of a component declaration
import { Component } from '@angular/core';

@Component({
selector: 'app-example',
template: '<p>This is an example component.</p>',
styles: ['p { font-weight: bold; }']
})
export class ExampleComponent {
// Component logic goes here
}

In this example, ExampleComponent is declared using the @Component decorator with a selector (app-example), template, and styles.

2. Directives: Directives are markers on a DOM element that tell Angular to attach a specific behavior to it. There are two types of directives: structural and attribute directives.

// Example of a directive declaration
import { Directive, ElementRef }…

--

--

Pravin M
Pravin M

Written by Pravin M

I am a frontend developer with 10+ years of experience Blog :- https://www.frontendinterviewquestions.com