Cannot read property 'nativeElement' of undefined - ngAfterViewInit

后端 未结 1 1297
生来不讨喜
生来不讨喜 2021-01-06 14:26

I\'m trying to add a \"clipboard\" directive using this example. The example is now outdated so I have had to update how it is getting the nativeElement.

I\'m gettin

1条回答
  •  时光说笑
    2021-01-06 14:36

    You name ElementRef as eltRef but try to use this.el in ngAfterViewInit. You need to use the same name.

    this will work:

    constructor(private el:ElementRef) {
    }
    
    ngAfterViewInit() {
      this.clipboard = new Clipboard(this.el.nativeElement, { 
      target: () => {
        return this.elt;
      }
    } 
    

    0 讨论(0)
提交回复
热议问题