填写这份《一分钟调查》,帮我们(开发组)做得更好!去填写Home

NG1001: Decorator argument is not an object literal
装饰器参数不是对象字面量

说明

Description

为了使 Angular 编译器中的元数据提取更快,装饰器 @NgModule@Pipe@Component@Directive@Injectable 只能接受对象字面量作为参数。

To make the metadata extraction in the Angular compiler faster, the decorators @NgModule, @Pipe, @Component, @Directive, and @Injectable accept only object literals as arguments.

这是 Ivy 中的有意更改,与 View Engine 相比,它对装饰器强制执行更严格的参数要求。 Ivy 需要这种方法,因为它通过将表达式移到类输出中的其他位置来编译这些装饰器。

This is an intentional change in Ivy, which enforces stricter argument requirements for decorators than View Engine. Ivy requires this approach because it compiles decorators by moving the expressions into other locations in the class output.


如何排除本错误

Debugging the error

把所有声明:

Move all declarations:

      
      const moduleDefinition = {...}

@NgModule(moduleDefinition)
export class AppModule {
    constructor() {}
}
    

移入装饰器:

into the decorator:

      
      @NgModule({...})
export class AppModule {
    constructor() {}
}