angular – decorator中不支持函数调用

前端之家收集整理的这篇文章主要介绍了angular – decorator中不支持函数调用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试使用-aot选项(ng build -aot)构建应用程序.我有以下错误
ERROR in Error during template compile of 'MyComponent'
  Function calls are not supported in decorators but 'classLogger' was called in 'cLog'
    'cLog' calls 'classLogger'.

但是我需要这个调用,我不知道我应该如何更改代码以使其工作.

export function classLogger(_classOptions?) {
   const myLogger = new MyLogger();
   myLogger.options = Object.assign({},defaultClassOptions,_classOptions);

   return myLogger.loggerCB;
}

// export function clog(options = defaultClassOptions): Function {
export function cLog(options?): Function {
   return loggingEnabled ? classLogger(options) : emptyClassDecorator();
}

附:类装饰器接受必须转移到装饰器补丁回调的选项.

我也遇到过这个问题.在我的情况下,我想覆盖BusyConfig参数.应用程序适用于ng服务,但是当我想为生产构建应用程序时,修饰符不支持函数调用但是…发生异常.

我的解决方案如下:
ng build –prod –aot = false

The Angular Ahead-of-Time (AOT) compiler converts your Angular HTML
and TypeScript code into efficient JavaScript code during the build
phase before the browser downloads and runs that code.

ng build –prod与ng build –prod –aot相同

原文链接:https://www.f2er.com/angularjs/141773.html

猜你在找的Angularjs相关文章