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 {}
The standalone property must be set to true to declare a standalone component in Angular.
Complete the code to import the CommonModule in an Angular standalone component.
import { Component } from '@angular/core'; import { [1] } from '@angular/common'; @Component({ selector: 'app-sample', standalone: true, imports: [CommonModule], template: `<p>Sample works!</p>` }) export class SampleComponent {}
The CommonModule provides common directives like ngIf and ngFor and must be imported explicitly in standalone components.
Fix the error in the exports array of an Angular NgModule.
import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import { FeatureComponent } from './feature.component'; @NgModule({ declarations: [FeatureComponent], imports: [CommonModule], exports: [[1]] }) export class FeatureModule {}
The exports array should list components, directives, or pipes to make them available outside the module. Here, FeatureComponent is correct.
Fill both blanks to correctly import and export a component in an Angular NgModule.
import { NgModule } from '@angular/core'; import { SharedComponent } from './shared.component'; @NgModule({ declarations: [[1]], exports: [[2]] }) export class SharedModule {}
You must declare the component in declarations and export the same component in exports to share it with other modules.
Fill all three blanks to create a standalone component that imports FormsModule and exports itself.
import { Component } from '@angular/core'; import { [1] } from '@angular/forms'; @Component({ selector: 'app-input', standalone: true, imports: [[2]], template: `<input [(ngModel)]="name" />` }) export class [3] { name = ''; }
To use two-way binding with ngModel, you must import FormsModule. The component class name is InputComponent.