填寫這份《一分鐘調查》,幫我們(開發組)做得更好!去填寫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() {}
}