First, App imports the Book Card class, from its file. Then the imports array in the decorator, tells Angular this template may use it. Now the template can use the app book card tag, as many times as we like. Run it. Two book cards appear, under the heading.
app.tstypescript
import { Component } from '@angular/core';import { BookCard } from './book-card';@Component({ selector: 'app-root', imports: [BookCard], template: ` <h1>New this week</h1> <app-book-card /> <app-book-card /> `,})export class App {}
Also uses book-card.ts
import { Component } from '@angular/core';@Component({ selector: 'app-book-card', template: ` <div class="card"> <h3>Dune</h3> <p>Frank Herbert · £9.99</p> </div> `,})export class BookCard {}
This time, we forget the imports array. Run it. The build fails. Angular says, app book card is not a known element. So when you see that error, check the imports array first.
app.tstypescript
import { Component } from '@angular/core';import { BookCard } from './book-card';@Component({ selector: 'app-root', template: ` <h1>New this week</h1> <app-book-card /> <app-book-card /> `,})export class App {}
Output
✘ [ERROR] NG8001: 'app-book-card' is not a known element:
1. If 'app-book-card' is an Angular component, then verify that it is included in the
'@Component.imports' of this component.
2. If 'app-book-card' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the
'@Component.schemas' of this component to suppress this message. Find more at
https://next.angular.dev/errors/NG8001
src/app/app.ts:8:4:
8 │ <app-book-card />
╵ ~~~~~~~~~~~~~~~~~
Also uses book-card.ts
import { Component } from '@angular/core';@Component({ selector: 'app-book-card', template: ` <div class="card"> <h3>Dune</h3> <p>Frank Herbert · £9.99</p> </div> `,})export class BookCard {}