Return to site
ANGULAR INTERVIEW QUESTION: Can you define what is a component in Angular?📦
ANGULAR INTERVIEW QUESTION: Can you define what is a component in Angular?📦
A component is the most basic element🧬 of user interface in an Angular Application.
Furthermore, an Angular application can be viewed like a plain components tree.📦🌳
More precisely, a component is always composed of
―a TypeScript class for the business logic👨💼, with an @Component annotation, and of
―an HTML template🎨.
👇👇👇
Component snippet:
import { Component } from '@angular/core'; @Component({ selector: 'app-root', templateUrl: './app.component.html', }) export class AppComponent { title = 'My App'; }
A component must always belong to a module to be used in your application or in another module.
👇👇👇
Module snippet:
importˑˑ{ NgModule } from '@angular/core'; importˑˑ{ AppComponent } from './app.component'; @NgModule({ declarations: [AppComponent], imports: [], bootsrap: [AppComponent] }) export class AppModule {}