Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular2 - ngx-clipboard not working

I installed ngx-clipboard as mentioned in the documentation and included the js in systemjs.config as well. However I am getting below error:

Unhandled Promise rejection: Template parse errors:
Can't bind to 'ngxClipboard' since it isn't a known property of 'button'. ("  </div>

Here is my template:

<div class="col-xs-12 share-pageurl-label">
                    <a #copyTarget>{{pageURL}}</a>
                </div>
                <div class="col-xs-12 share-copy-btn">
                    <button [(ngxClipboard)]="copyTarget" (cbOnSuccess)="linkCopied()" 
                    [ngClass]="{linkCopied: isCopied}">
                        {{copyBtnLabel}} <span *ngIf="isCopied" class="glyphicon glyphicon-ok"></span>
                    </button>
                </div>
like image 551
Peter Avatar asked Sep 06 '25 03:09

Peter


1 Answers

I believe you'll get this error if you have not imported the ClipBoardModule correctly. If you have nested modules and want to use in a lower level, you'll have to make sure that you export this on a parent module, and import on a child module.

parent.module

import { ClipboardModule } from 'ngx-clipboard';

@NgModule({
  declarations: [],
  imports: [
    ClipboardModule
  ],
  exports: [
    ClipboardModule,
  ]
})
export class ParentModule {
}

child.module

import { ParentModule } from '../../parent.module';

@NgModule({
imports: [
  ParentModule,
],
declarations: []
})
export class ChildModule {
}
like image 151
Erkin Djindjiev Avatar answered Sep 07 '25 19:09

Erkin Djindjiev