refactor(docs-infra): use CDK clipboard service (#40840)

The CDK has had a service for copying strings to the clipboard. These changes switch
AIO to it, rather than having to maintain a custom solution.

PR Close #40840
This commit is contained in:
Kristiyan Kostadinov
2021-02-16 07:43:56 -08:00
committed by Joey Perrott
parent 5f0c219883
commit f2ee9d5679
4 changed files with 15 additions and 116 deletions
@@ -1,7 +1,7 @@
import { Component, ElementRef, EventEmitter, Input, OnChanges, Output, ViewChild } from '@angular/core';
import { Clipboard } from '@angular/cdk/clipboard';
import { Logger } from 'app/shared/logger.service';
import { PrettyPrinter } from './pretty-printer.service';
import { CopierService } from 'app/shared/copier.service';
import { MatSnackBar } from '@angular/material/snack-bar';
import { tap } from 'rxjs/operators';
@@ -96,7 +96,7 @@ export class CodeComponent implements OnChanges {
constructor(
private snackbar: MatSnackBar,
private pretty: PrettyPrinter,
private copier: CopierService,
private clipboard: Clipboard,
private logger: Logger) {}
ngOnChanges() {
@@ -144,7 +144,7 @@ export class CodeComponent implements OnChanges {
/** Copies the code snippet to the user's clipboard. */
doCopy() {
const code = this.codeText;
const successfullyCopied = this.copier.copyText(code);
const successfullyCopied = this.clipboard.copy(code);
if (successfullyCopied) {
this.logger.log('Copied code to clipboard:', code);