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 a standalone component into another standalone component.
import { Component } from '@angular/core'; import { HelloComponent } from './hello.component'; @Component({ selector: 'app-main', template: `<app-hello></app-hello>`, standalone: true, imports: [[1]] }) export class MainComponent {}
Standalone components must be imported by listing them in the imports array of the consuming standalone component.
Fix the error in this module-based Angular module declaration.
import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { HelloComponent } from './hello.component'; @NgModule({ declarations: [[1]], imports: [BrowserModule], bootstrap: [HelloComponent] }) export class AppModule {}
The component to be declared in the module must be listed in the declarations array. Here, HelloComponent is the correct component.
Fill both blanks to create a standalone component that uses CommonModule and FormsModule.
import { Component } from '@angular/core'; import { [1] } from '@angular/common'; import { [2] } from '@angular/forms'; @Component({ selector: 'app-form', template: `<form></form>`, standalone: true, imports: [CommonModule, FormsModule] }) export class FormComponent {}
To use common directives and forms features in a standalone component, import CommonModule from '@angular/common' and FormsModule from '@angular/forms'.
Fill all three blanks to convert a module-based component to standalone with imports.
import { Component } from '@angular/core'; import { [1] } from '@angular/common'; import { [2] } from '@angular/forms'; @Component({ selector: 'app-user', template: `<input [(ngModel)]="name">`, standalone: [3], imports: [CommonModule, FormsModule] }) export class UserComponent { name = ''; }
To make the component standalone, set standalone to true and import CommonModule and FormsModule for common directives and forms support.