5 lines
3.1 KiB
JSON
Raw Permalink Normal View History

{
"id": "errors/NG0201",
"title": "NG0201: No provider for {token} found!",
"contents": "<h1 id=\"ng0201-no-provider-for-token-found\">NG0201: No provider for {token} found!<a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"errors/NG0201#ng0201-no-provider-for-token-found\"><i class=\"material-icons\">link</i></a></h1>\n<div class=\"github-links\">\n <a href=\"https://github.com/angular/angular/edit/master/aio/content/errors/NG0201.md?message=docs(...)%3A%20describe%20your%20change...\" aria-label=\"Suggest Edits\" title=\"Suggest Edits\"><i class=\"material-icons\" aria-hidden=\"true\" role=\"img\">mode_edit</i></a>\n</div>\n\n\n<div class=\"error-video-container\">\n <iframe src=\"https://www.youtube.com/embed/lAlOryf1-WU\" frameborder=\"0\" allow=\"accelerometer; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen></iframe>\n</div>\n\n\n\n<div class=\"content\">\n <h2 id=\"description\">Description<a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"errors/NG0201#description\"><i class=\"material-icons\">link</i></a></h2>\n <p>You see this error when you try to inject a service but have not declared a corresponding provider. A provider is a mapping that supplies a value that you can inject into the constructor of a class in your application.</p>\n<p>Read more on providers in our <a href=\"guide/dependency-injection\">Dependency Injection guide</a>.</p>\n\n</div>\n<br>\n<div class=\"debugging\">\n <h2 id=\"debugging-the-error\">Debugging the error<a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"errors/NG0201#debugging-the-error\"><i class=\"material-icons\">link</i></a></h2>\n <p>Work backwards from the object where the error states that a <a href=\"guide/architecture-services\">provider</a> is missing: <code>No provider for ${this}!</code>. This is commonly thrown in <a href=\"tutorial/toh-pt4\">services</a>, which require non-existing providers.</p>\n<p>To fix the error ensure that your service is registered in the list of providers of an <code><a href=\"api/core/NgModule\" class=\"code-anchor\">NgModule</a></code> or has the <code>@<a href=\"api/core/Injectable\" class=\"code-anchor\">Injectable</a></code> decorator with a <code>providedIn</code> property at top.</p>\n<p>The most common solution is to add a provider in <code>@<a href=\"api/core/Injectable\" class=\"code-anchor\">Injectable</a></code> using <code>providedIn</code>:</p>\n<code-example language=\"typescript\">\n@<a href=\"api/core/Injectable\" class=\"code-anchor\">Injectable</a>({ providedIn: 'app' })\n</code-example>\n\n</div>\n\n<!-- links to this doc:\n - errors\n - errors/NG2003\n-->\n<!-- links from this doc:\n - api/core/Injectable\n - api/core/NgModule\n - errors/NG0201#debugging-the-error\n - errors/NG0201#description\n - errors/NG0201#ng0201-no-provider-for-token-found\n - guide/architecture-services\n - guide/dependency-injection\n - tutorial/toh-pt4\n - https://github.com/angular/angular/edit/master/aio/content/errors/NG0201.md?message=docs(...)%3A%20describe%20your%20change...\n-->"
}