Complete the code to declare a standalone component in Angular.
import { Component } from '@angular/core'; @Component({ selector: 'app-hello', template: `<h1>Hello World</h1>`, standalone: [1] }) export class HelloComponent {}
Setting standalone: true makes the component standalone, so it doesn't need to be declared in an NgModule.
Complete the code to import the CommonModule in a standalone component.
import { Component } from '@angular/core'; import { [1] } from '@angular/common'; @Component({ selector: 'app-example', standalone: true, imports: [CommonModule], template: `<p>Example works!</p>` }) export class ExampleComponent {}
The CommonModule provides common directives like ngIf and ngFor which are often needed in templates.
Fix the error in the standalone component declaration by completing the missing property.
import { Component } from '@angular/core'; @Component({ selector: 'app-fix', template: `<p>Fix me!</p>`, [1]: true }) export class FixComponent {}
The property standalone must be set to true to declare a standalone component.
Fill both blanks to create a standalone component that imports FormsModule and declares a template with two-way binding.
import { Component } from '@angular/core'; import { [1] } from '@angular/forms'; @Component({ selector: 'app-input', standalone: true, imports: [[2]], template: `<input [(ngModel)]="name" /> <p>Hello {{name}}</p>` }) export class InputComponent { name = ''; }
To use two-way binding with ngModel, you must import FormsModule and include it in the imports array.
Fill all three blanks to create a standalone component that imports RouterModule, uses inject() to get Router, and navigates on button click.
import { Component, [1] } from '@angular/core'; import { [2], Router } from '@angular/router'; @Component({ selector: 'app-navigate', standalone: true, imports: [RouterModule], template: `<button (click)="goHome()">Go Home</button>` }) export class NavigateComponent { router = [3](Router); goHome() { this.router.navigate(['/home']); } }
Use inject from '@angular/core' to get the Router instance. Import RouterModule for routing features.