Angular·Angular from components to production

Components and templates

Create components with typed inputs and clean templates.

Intermediate 13 min read Lesson 2 of 300 Challenge included
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.

lesson-card.component.tsTYPESCRIPT
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

Add an input

Easy

Add a required slug input to a standalone component.

TYPESCRIPT · starter
@Input() slug: string
Check 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 in
Finished reading?

Lock in what you just learned.

Mark this lesson complete to save your place and move one step closer to the certificate.

Next: Binding and events
Lesson 2 of 300 · 0% of course