0

trying to use ngx-clipboard v.7.0.6 and use ClipboardService inside my component and getting this error: Promise rejection: No provider for Token DOCUMENT! ;

Module:

import {NgModule}                         from '@angular/core';
import {CommonModule}                     from '@angular/common';
import {BrowserModule}                    from '@angular/platform-browser';
import {RouterModule}                     from '@angular/router';
import {ReactiveFormsModule}              from '@angular/forms';
import {ClipboardModule}                  from 'ngx-clipboard';
import {ClipboardService}                 from 'ngx-clipboard/src';

@NgModule({
  imports: [
    CommonModule,
    ClipboardModule,
    BrowserModule,
    RouterModule,
    ReactiveFormsModule
  ],
  declarations: [],
  providers: [
    ClipboardService
  ]
})

export class MyModule {}

Component:

import {Renderer} from '@angular/core';
import {ClipboardService} from 'ngx-clipboard/src';

@Component({
  selector: 'app-my',
  templateUrl: '../tmp.html',
  styleUrls: ['../tmp.css']
})
export class MyComponent {
  constructor(
    private renderer: Renderer,
    private clipboardService: ClipboardService
  ) {}

  copy(text) {
    this.clipboardService.copyFromContent(text, this.renderer);
  }
}

2 Answers2

0

Install ngx-clipboard version 12.1.1.

Replace the version in your package.json from x.x to "ngx-clipboard": "12.1.1"

Reference : https://github.com/maxisam/ngx-clipboard/issues/190

Ashwin R
  • 744
  • 7
  • 14
-1

try to add the ClipboardModule in the app's declaration

import {NgModule}                         from '@angular/core';
import {CommonModule}                     from '@angular/common';
import {BrowserModule}                    from '@angular/platform-browser';
import {RouterModule}                     from '@angular/router';
import {ReactiveFormsModule}              from '@angular/forms';
import {ClipboardModule}                  from 'ngx-clipboard';
import {ClipboardService}                 from 'ngx-clipboard/src';

@NgModule({
  imports: [
    CommonModule,
    ClipboardModule,
    BrowserModule,
    RouterModule,
    ReactiveFormsModule
  ],
  declarations: [ClipboardModule],
  providers: [
    ClipboardService
  ]
})

export class MyModule {}
cnnr
  • 1,267
  • 4
  • 18
  • 23
L.Sarah
  • 11
  • 1