Angular & Signals (283 Qs)•Part 1: Architecture, Components, Directives & Lifecycle (1 - 35)
What are the key components of Angular?
Angular has the key components below,
- Component: These are the basic building blocks of an Angular application to control HTML views.
- Modules: An Angular module is a set of angular basic building blocks like components, directives, services etc. An application is divided into logical pieces and each piece of code is called as "module" which perform a single task.
- Templates: These represent the views of an Angular application.
- Services: Are used to create components which can be shared across the entire application.
- Metadata: This can be used to add more data to an Angular class.
Practical Code Example
typescript
// Key Angular Building Blocks: Component, Template, Metadata, Service, Dependency Injection
import { Component, Injectable } from '@angular/core';
@Injectable({ providedIn: 'root' })
export class DataService {
getData() { return ['Angular', 'TypeScript', 'RxJS']; }
}
@Component({
selector: 'app-demo',
standalone: true,
template: `<ul>@for (item of items; track item) { <li>{{ item }}</li> }</ul>`
})
export class DemoComponent {
items = this.dataService.getData();
constructor(private dataService: DataService) {}
}