Are ES6 arrow functions incompatible with Angular?

半城伤御伤魂 提交于 2019-11-29 05:58:10

Correct. Your version of AngularJS is not compatible with arrow functions that make use of $injector.

This is mainly because AngularJS 1.4.6 makes use of (Function).toString, which does not start with function( for arrow functions, at least in Firefox:

>var a = () => 5
function a()
>a.toString()
"() => 5"  // not "function a() {return 5;}"

AngularJS supports the arrow notation from 1.5.0 onwards.

I tried another variation which worked: (x)=>… (instead of x=>…)

app.run(($templateCache) => $templateCache.put('/some','thing'));

I guess it needs parentheses for some reason

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!