Complete the code to define a standalone Angular component.
import { Component } from '@angular/core'; @Component({ selector: 'app-hello', template: '<h1>Hello World</h1>', standalone: [1] }) export class HelloComponent {}
The standalone: true flag makes the component standalone, meaning it does not require a module.
Complete the code to import a component into an Angular 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 import other standalone components by listing them in the imports array.
Fix the error in the module definition by completing the missing metadata.
import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { AppComponent } from './app.component'; @NgModule({ declarations: [AppComponent], imports: [[1]], bootstrap: [AppComponent] }) export class AppModule {}
The BrowserModule must be imported in the root module to enable browser-specific services.
Fill both blanks to create a feature module that exports a component.
import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import { FeatureComponent } from './feature.component'; @NgModule({ declarations: [[1]], imports: [[2]], exports: [FeatureComponent] }) export class FeatureModule {}
The feature module declares its own component and imports CommonModule for common directives.
Fill all three blanks to define a standalone component that uses a service and another component.
import { Component } from '@angular/core'; import { CommonModule } from '@angular/common'; import { DataService } from './data.service'; import { ChildComponent } from './child.component'; @Component({ selector: 'app-parent', template: '<app-child></app-child>', standalone: [1], imports: [[2]], providers: [[3]] }) export class ParentComponent {}
The component is standalone (true), imports the child component, and provides the data service.