Our first component

In this section, we are going to look at our first Angular component. Earlier in this chapter, we learned how to bootstrap an Angular application, and we used the AppModule. Later, we learned that the AppModule uses the AppComponent as the root component of our application. We will now look at the AppComponent:

import { Component } from "@angular/core"; 
 
@Component({ 
    selector: "app-root", 
    template: ` 
    <app-layout></app-layout>`, 
}) 
export class AppComponent { 
} 

As you can see, in Angular, a component is a class decorated with the @Component decorator. The @Component decorator takes some settings.

In this case, we use the selector setting to declare the name used to reference this component within a template. The AppComponent ...

Get Learning TypeScript 2.x - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.