Interacting with the clipboard
The Angular CDK library contains a collection of Angular artifacts that we can use to interact with the system clipboard. Specifically, it includes a directive for copying data to the clipboard and an event binding for taking additional action when the content has been copied. Let's see how we can integrate both in our component library, as follows:
- Execute the following command of the Angular CLI to create a new Angular component in the library:
ng generate component copy-button --project=ui-controls --export
- Export the newly generated component from the
public-api.ts
file as follows:
export * from './lib/copy-button/copy-button.component';
- Open the
ui-controls.module.ts
file and importClipboardModule
from the@angular/cdk/clipboard
namespace, like this:
import { ClipboardModule } from '@angular/cdk/clipboard';
- Add the
ClipboardModule
class to theimports
array of the@NgModule
decorator like this:
@NgModule({
...