小编Kil*_*lan的帖子

NullInjectorError: No provider for ElementRef

I created an internal directive in a module in my project (Angular 8 + Material Design). Following tuto and official doc.

@Directive({
  selector: '[button-confirmation]'
})
export class ButtonConfirmationDirective {

  @Output('bc-confirm')
  confirmAction = new EventEmitter<any>();

  @Input('bc-options')
  options: Option[] = [...];

  constructor(
    private el: ElementRef,
    private confirmationService: ConfirmationService
  ) { }

  @HostListener('mouseup') onMouseUp() {
    this.confirmationService.displayConfirm(this.el, this.options, this.confirmAction);
  }

}
Run Code Online (Sandbox Code Playgroud)

Ok, it's work. BUT, when i create an external library and move my directive (with components, services, ...) i got the error : …

angular-directive angular-material angular-module angular angular-library

5
推荐指数
2
解决办法
7126
查看次数