跳到正文
本页尚未翻译成中文,以下为英文原文。 查看英文版

Clean up unused imports ​

As of version 19, Angular reports when a component's imports array contains symbols that aren't used in its template.

Running this schematic will clean up all unused imports within the project.

Run the schematic using the following command:

shell
ng generate @angular/core:cleanup-unused-imports

Before ​

ts
import {Component} from '@angular/core';
import {UnusedDirective} from './unused';

@Component({
  template: 'Hello',
  imports: [UnusedDirective],
})
export class MyComp {}

After ​

ts
import {Component} from '@angular/core';

@Component({
  template: 'Hello',
  imports: [],
})
export class MyComp {}

基于 MIT 许可证发布。