Angular2 No provider for Renderer! (NgModel -> Token NgValueAccessor -> DefaultValueAccessor -> Renderer)

£可爱£侵袭症+ 提交于 2019-12-10 20:49:13

问题


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

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

Please help me resovle this issue. Thanks.


回答1:


I see two possibilities:

  • 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.

    Something like that:

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

    @Component({
      selector: 'child',
      template: '<div></div>',
    })
    export class ChildComponent {
      constructor(private _renderer: Renderer,
               private el: ElementRef) {
        (...)
      }
    }
  • 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.

Edit

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})
]);

Hope it helps you, Thierry




回答2:


You probably need to add in your component decorator

@Component({
  providers: [Renderer],
  ...
)}


来源:https://stackoverflow.com/questions/34606534/angular2-no-provider-for-renderer-ngmodel-token-ngvalueaccessor-defaultv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!