Angular2 没有渲染器的提供者!(NgModel -> Token NgValueAccessor -> DefaultValueAccessor -> Renderer) [英] Angular2 No provider for Renderer! (NgModel -> Token NgValueAccessor -> DefaultValueAccessor -> Renderer)

查看:21
本文介绍了Angular2 没有渲染器的提供者!(NgModel -> Token NgValueAccessor -> DefaultValueAccessor -> Renderer)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 shlomiassaf/angular2-modal 中自定义了 customModal.ts 的模态.具体来说,我添加了一个包含 ngModel 的输入,它导入了 FORM_DIRECTIVES 和指令.

I custom modal of customModal.ts in shlomiassaf/angular2-modal. Specific, i add a input contain ngModel, it imported FORM_DIRECTIVES and directives.

运行'No provider for Renderer! 时的问题!(NgModel -> Token NgValueAccessor -> DefaultValueAccessor -> Renderer)'

The issue when run 'No provider for Renderer! (NgModel -> Token NgValueAccessor -> DefaultValueAccessor -> Renderer)'

请帮我解决这个问题.谢谢.

Please help me resovle this issue. Thanks.

推荐答案

我看到两种可能性:

  • 未在组件或应用程序级别指定相应的提供程序.我认为这不是问题,因为我已经注入了 Renderer 而没有在其 providers 属性中或 bootstrap 功能.

  • The corresponding provider isn't specified at the component or application level. I don't think that the problem because I already inject a Renderer without having specified it in its providers attribute or within the second parameter of the bootstrap function.

类似的东西:

    import {Component,Renderer,ElementRef} from 'angular2/core';

    @Component({
      selector: 'child',
      template: '<div></div>',
    })
    export class ChildComponent {
      constructor(private _renderer: Renderer,
               private el: ElementRef) {
        (...)
      }
    }

  • 我认为这更像是因为注入渲染器的类没有被修饰,所以依赖注入不能应用.正如此评论中所强调的那样,您需要拥有它才能注入.Injectable 不是为了注入到某个东西中,而是为了注入到自身中.
    • I think it would be rather because the class where the renderer is injected isn't decorated so dependency injection can't apply. As emphasized in this comment, you need to have this to be able to inject. Injectable isn't for be injected into something but for injecting into itself.
    • 编辑

      在查看您的代码后,您似乎需要将渲染器添加到您提供给 loadNextToLocation 方法的提供程序列表中.您可以像这样更新 DialogService#open 方法的代码:

      After having a look at your code, it seems that you need to add the renderer to the list of providers you provide to the loadNextToLocation method. You could update the code of the DialogService#open method like this:

      var otherResolved = Injector.resolve([
        provide(DialogRef, { useValue: dialogRef})
        provide(Renderer, { useValue: this.renderer})
      ]);
      

      希望对你有帮助蒂埃里

      这篇关于Angular2 没有渲染器的提供者!(NgModel -> Token NgValueAccessor -> DefaultValueAccessor -> Renderer)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆