在Angular 9中,引入依赖项时有所变化。现在,@angular/core库中的许多公共API已经被移动到新的包中。 在应用程序中导入这些API的方式有所改变。下面是一个示例:
在Angular 8中,我们可以这样导入:
import {Component} from '@angular/core';
在Angular 9中,我们可能需要这样导入:
import {Component} from '@angular/core';
import {ɵɵdefineComponent} from '@angular/core';
请注意,新的导入路径中使用了ɵ前缀。这是一个命名约定,用于标识Angular内部使用的API。
import {ɵɵdefineComponent} from '@angular/core';
@Component({ selector: 'app-example', template: 'Hello World' }) export class ExampleComponent { // Component logic goes here }
export class ExampleModule { // Module logic goes here }
@NgModule({ declarations: [ExampleComponent], imports: [], exports: [ExampleComponent], })
简而言之,如果你已经在Angular 8或早期版本中编写了代码,其中使用了@angular/core中的公共API,请在将应用程序迁移到Angular 9时确保按照新的导入方式进行修改。