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, removing the need for NgModules.
Complete the code to import the CommonModule in a standalone component.
import { Component } from '@angular/core'; import { [1] } from '@angular/common'; @Component({ selector: 'app-list', template: `<ul><li *ngFor="let item of items">{{item}}</li></ul>`, standalone: true, imports: [CommonModule] }) export class ListComponent { items = ['One', 'Two', 'Three']; }
The CommonModule provides common directives like *ngFor and *ngIf needed in templates.
Fix the error in the standalone component by completing the imports array.
import { Component } from '@angular/core'; import { RouterModule } from '@angular/router'; @Component({ selector: 'app-nav', template: `<a routerLink="/home">Home</a>`, standalone: true, imports: [[1]] }) export class NavComponent {}
The RouterModule must be imported in standalone components to use routerLink directive.
Fill both blanks to define a standalone component that uses FormsModule and declares a template variable.
import { Component } from '@angular/core'; import { [1] } from '@angular/forms'; @Component({ selector: 'app-input', template: `<input #inputRef type="text" [(ngModel)]="name">`, standalone: true, imports: [[2]] }) export class InputComponent { name = ''; }
The FormsModule is needed to use ngModel for two-way binding in standalone components.
Fill all three blanks to create a standalone component that imports CommonModule, uses a signal, and displays its value.
import { Component, signal } from '@angular/core'; import { [1] } from '@angular/common'; @Component({ selector: 'app-counter', template: `<button (click)="increment()">Increment</button> <p *ngIf="count()">Count: {{ count() }}</p>`, standalone: true, imports: [[2]] }) export class CounterComponent { count = [3](0); increment() { this.count.update(c => c + 1); } }
The component imports CommonModule for common directives and uses Angular's signal to create a reactive state.