Components and templates
Create components with typed inputs and clean templates.
What you will be able to do
- Use @Component with a template or templateUrl.
- Declare typed @Input values.
- Keep templates free of complex logic.
- Use standalone imports for dependencies.
In plain English
A component owns a template and a class. Use @Input to receive data and keep the template declarative. Standalone components import what they need instead of relying on a module.
import { Component, Input } from '@angular/core'
@Component({
selector: 'app-lesson-card',
standalone: true,
template: `
<article>
<h2>{{ title }}</h2>
<p>{{ minutes }} minutes</p>
</article>
`,
})
export class LessonCardComponent {
@Input({ required: true }) title!: string
@Input() minutes = 10
}Your turn
EasyAdd an input
Add a required slug input to a standalone component.
TYPESCRIPT · starter
@Input() slug: stringCheck your understanding before moving on.
Knowledge checkQuestion 1
What decorator marks a class as an Angular component?
Select an answer to continue
Study tools
Make it yours.
Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.
Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign inFinished reading?
Lock in what you just learned.
0%
Mark this lesson complete to save your place and move one step closer to the certificate.