gpt4 book ai didi

angular - 装饰器不支持函数调用

转载 作者:太空狗 更新时间:2023-10-29 17:15:45 24 4
gpt4 key购买 nike

我正在尝试使用 -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 serve 一起正常工作,但是当我想为生产构建应用程序时 装饰器不支持函数调用,但是 ... 发生异常。

我的解决方案如下: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

关于angular - 装饰器不支持函数调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48043003/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com