24 lines
1.5 KiB
HTML
Executable file
24 lines
1.5 KiB
HTML
Executable file
<a href="http://github.com/angular/angular.js/edit/master/docs/content/error/injector/itkn.ngdoc" class="improve-docs btn btn-primary"><i class="icon-edit"> </i> Improve this doc</a><h1><code ng:non-bindable="">Bad Injection Token</code>
|
|
<div><span class="hint">error in component <code ng:non-bindable="">$injector</code>
|
|
</span>
|
|
</div>
|
|
</h1>
|
|
<div><pre class="minerr-errmsg" error-display="Incorrect injection token! Expected service name as string, got {0}">Incorrect injection token! Expected service name as string, got {0}</pre>
|
|
<h2 id="Description">Description</h2>
|
|
<div class="description"><div class="-injector-page -injector-itkn-page"><p>This error occurs when using a bad token as a dependency injection annotation.
|
|
Dependency injection annotation tokens should always be strings. Using any other
|
|
type will cause this error to be thrown.</p>
|
|
<p>Examples of code with bad injection tokens include:</p>
|
|
<pre><code>var myCtrl = function ($scope, $http) { /* ... */ };
|
|
myCtrl.$inject = ['$scope', 42];
|
|
|
|
myAppModule.controller('MyCtrl', ['$scope', {}, function ($scope, $timeout) {
|
|
// ...
|
|
}]);</code></pre>
|
|
<p>The bad injection tokens are <code>42</code> in the first example and <code>{}</code> in the second.
|
|
To avoid the error, always use string literals for dependency injection annotation
|
|
tokens.</p>
|
|
<p>For an explanation of what injection annotations are and how to use them, refer
|
|
to the <a href="guide/di">Dependency Injection Guide</a>.</p>
|
|
</div></div>
|
|
</div>
|