Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular itkn error caused by directives defined with function outside array

I'm using Angular 1.3.15, also have tried 1.2.28, along with angular bootstrap. Last night, after updating Chrome to v42.0.2311.90, I suddenly began seeing tons of angular itkn errors:

Error: [$injector:itkn] Incorrect injection token! Expected service name as string, got function ()
http://errors.angularjs.org/1.3.15/$injector/itkn?p0=function%20()
    at REGEX_STRING_REGEXP (angular.min.js?bust=undefined:63)
    at Object.invoke (angular.min.js?bust=undefined:4189)
    at angular.min.js?bust=undefined:6525
    at forEach (angular.min.js?bust=undefined:323)
    at Object.<anonymous> (angular.min.js?bust=undefined:6523)
    at Object.invoke (angular.min.js?bust=undefined:4204)
    at Object.enforcedReturnValue [as $get] (angular.min.js?bust=undefined:4056)
    at Object.invoke (angular.min.js?bust=undefined:4204)
    at angular.min.js?bust=undefined:4021
    at Object.getService [as get] (angular.min.js?bust=undefined:4162)

This wasn't happening before updating Chrome but I guess I can't say that's for sure related.

After poking through, I've found that any directives defined like this:

  .directive('modalTransclude', function () {
    return {
      // directive code
    };
  })

Will cause this itkn error. I console.logged the key in the $inject iterator in angular and it's returning the function of the directive itself rather than only strings like was clearly intended.

I've discovered that wrapping the function in an array, even without any strings defining the injections, it solves the issue:

  .directive('modalTransclude', [function () {
    return {
      // directive code
    };
  }])

However, this error is not happening on the angular bootstrap site, and I've tried this on both angular 1.3 and 1.2 versions.

I'll continue looking for any causes that are unique to my app, but does anyone have any idea what's causing this?

like image 759
helion3 Avatar asked Apr 15 '15 15:04

helion3


2 Answers

If you have ng-inspector.org extension installed in chrome, it might be a reason. Just switch off ng-inspector browser extension.

I don't know exact reasons why it's not working with ng-inspector at the moment. If someone have time to look into this, it would be nice to submit bug to project involved (I suspect it's ng-inspector itself).

like image 125
Egor Smirnov Avatar answered Nov 11 '22 12:11

Egor Smirnov


This is indeed an issue that surfaced with version 0.5.9 of ng-inspector (I'm its maintainer) which was released yesterday. I'm already working on a solution for this, and will release it shortly.

I'm terribly sorry for the inconvenience =(

Edit: Just published v0.5.10, should fix this issue. If you encounter further difficulties, feel free to open an issue at https://github.com/rev087/ng-inspector/

like image 2
rev087 Avatar answered Nov 11 '22 12:11

rev087