-{"id":"errors/NG0200","title":"NG0200: Circular dependency in DI detected while instantiating a provider\n\nDI 在实例化服务提供者时检测到循环依赖","contents":"<div class=\"github-links\">\n <a href=\"https://github.com/ng-docs/angular-cn/edit/cn/aio/content/errors/NG0200.md?message=docs(...)%3A%20请简述你的修改...\" aria-label=\"提供编辑建议\" title=\"提供编辑建议\"><i class=\"material-icons\" aria-hidden=\"true\" role=\"img\">mode_edit</i></a>\n</div>\n\n<div class=\"content\">\n\n <h1 id=\"ng0200-circular-dependency-in-di-detected-while-instantiating-a-providerdi-在实例化服务提供者时检测到循环依赖\">NG0200: Circular dependency in DI detected while instantiating a provider\n\nDI 在实例化服务提供者时检测到循环依赖<a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"errors/NG0200#ng0200-circular-dependency-in-di-detected-while-instantiating-a-providerdi-在实例化服务提供者时检测到循环依赖\"><i class=\"material-icons\">link</i></a></h1>\n\n \n <div class=\"video-container\">\n <video controls=\"\">\n <source src=\"assets/videos/NG0200.webm\" type=\"video/webm\">\n <source src=\"assets/videos/NG0200.mp4\" type=\"video/mp4\">\n <track src=\"assets/videos/NG0200.en.vtt\" label=\"English\" kind=\"subtitles\" srclang=\"en\">\n <track src=\"assets/videos/NG0200.cn.vtt\" label=\"简体中文\" kind=\"subtitles\" srclang=\"zh-CN\">\n <track src=\"assets/videos/NG0200.tw.vtt\" label=\"正體中文\" kind=\"subtitles\" srclang=\"zh-TW\">\n </video>\n </div>\n \n \n\n <div class=\"error-description\">\n <h2 translation-result=\"on\" id=\"说明\">说明<a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"errors/NG0200#说明\"><i class=\"material-icons\">link</i></a></h2>\n <h2 translation-origin=\"off\" id=\"description\">Description<a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"errors/NG0200#description\"><i class=\"material-icons\">link</i></a></h2>\n <p translation-result=\"on\">当某个<a href=\"guide/hierarchical-dependency-injection\">服务的依赖项</a>直接或间接依赖于此服务本身时,便存在循环依赖项。比如,如果 <code>UserService</code> 依赖于 <code>EmployeeService</code>,而 <code>EmployeeService</code> 也依赖于 <code>UserService</code>。Angular 将不得不先实例化 <code>EmployeeService</code> 再创建 <code>UserService</code>,而 <code>EmployeeService</code> 又依赖于 <code>UserService</code> 本身。</p><p translation-origin=\"off\">A cyclic dependency exists when a <a href=\"guide/hierarchical-dependency-injection\">dependency of a service</a> directly or indirectly depends on the service itself. For example, if <code>UserService</code> depends on <code>EmployeeService</code>, which also depends on <code>UserService</code>. Angular will have to instantiate <code>EmployeeService</code> to create <code>UserService</code>, which depends on <code>UserService</code>, itself.</p>\n\n\n </div>\n\n\n \n <br>\n\n <div class=\"debugging\">\n <h2 translation-result=\"on\" id=\"如何排除本错误\">如何排除本错误<a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"errors/NG0200#如何排除本错误\"><i class=\"material-icons\">link</i></a></h2>\n <h2 translation-origin=\"off\" id=\"debugging-the-error\">Debugging the error<a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"errors/NG0200#debugging-the-error\"><i class=\"material-icons\">link</i></a></h2>\n <p translation-result=\"on\">使用调用栈来确定循环依赖项存在的位置。通过<a href=\"guide/dependency-injection-in-action\">源码映射</a>找出组件、模块或服务的依赖项,并找出导致此问题的循环,就能查看是否有任何子依赖项依赖于原始文件。</p><p translation-origin=\"off\">Use the call stack to determine where the cyclical dependency exists.\nYou will be able to see if any child dependencies rely on the original file by <a href=\"guide/dependency-injection-in-action\">mapping out</a> the component, module, or service's dependencies, and identifying the loop causing the problem.</p>\n\n<p translation-result=\"on\">打破依赖关系的这种循环以解决此错误。这通常意味着删除或重构依赖项以使其彼此不互相依赖。</p><p translation-origin=\"off\">Break this loop (or circle) of dependency to resolve this error. This most commonly means removing or refactoring the dependencies to not be reliant on one another.</p>\n\n<!-- links -->\n<!-- external links -->\n<!-- end links -->\n\n </div>\n \n</div>\n\n<!-- links to this doc:\n - errors\n-->\n<!-- links from this doc:\n - errors/NG0200#debugging-the-error\n - errors/NG0200#description\n - errors/NG0200#ng0200-circular-dependency-in-di-detected-while-instantiating-a-providerdi-在实例化服务提供者时检测到循环依赖\n - errors/NG0200#如何排除本错误\n - errors/NG0200#说明\n - guide/dependency-injection-in-action\n - guide/hierarchical-dependency-injection\n - https://github.com/ng-docs/angular-cn/edit/cn/aio/content/errors/NG0200.md?message=docs(...)%3A%20请简述你的修改...\n-->"}
0 commit comments