Are ES6 arrow functions incompatible with Angular? Are ES6 arrow functions incompatible with Angular? angularjs angularjs

Are ES6 arrow functions incompatible with Angular?


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 = () => 5function 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