在我的某个应用中,我需要 eval 函数。我搜索了一下,找不到替代它的东西。当我升级到 Angular 19 时,我在 build-watch 和 build-prod 中看到以下警告:
▲ [WARNING] Using direct eval with a bundler is not recommended and may cause problems [direct-eval]
src/frontend/app/statistics/statistics.component.ts:554:14:
554 │ eval(option['function'] + '(' + cpt + ')');
╵ ~~~~
You can read more about direct eval and bundling here: https://esbuild.github.io/link/direct-eval
在哪里可以禁用此警告?我没有找到任何 esbuild 配置(例如 eslint)或其他东西
谢谢
您能否尝试用类似以下内容替换该
eval
表达式:option['function']
我们获取可作为函数的字符串表达式this
并使用参数执行它cpt
。