Skip to content

forRoot bug ERROR in Error during template compile of 'AppModule' Function calls are not supported in decorators but 'AuthModule' was called. #9358

@dongjiyan

Description

@dongjiyan

version:

    "@angular/cli": "1.6.5",
    "@angular/*i": "^5.2.0"

ng build --prod model

error:
ERROR in Error during template compile of 'AppModule'
Function calls are not supported in decorators but 'AuthModule' was called.

    AuthModule.forRoot({
      login_url: `/passport/login`,
      ignores:[
        "passport/login",
        "assets/.*",
        "test.*"
      ]
    })

AuthModule:

@NgModule({
    declarations: [
    ],
    imports: [
    ],
    providers: [

    ],
    exports: [
    ]
})
export class AuthModule {
    public static forRoot(options?:any): ModuleWithProviders {
        if (options && options.ignores && options.ignores.length) {
            /**字符串数组,如果直接写正则会导致angular项目失败,应该是bug */
            options.ignores.map(str => new RegExp(str));
        }
        return {
            ngModule: AuthModule,
            providers: [
                { provide: DA_USER_OPTIONS_TOKEN, useValue: options },
                { provide: DA_OPTIONS_TOKEN, useFactory: optionsFactory, deps: [DA_USER_OPTIONS_TOKEN] },
                { provide: DA_STORE_TOKEN, useClass: LocalStorageStore },
                { provide: DA_SERVICE_TOKEN, useClass: TokenService }
            ]
        };
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions