Geesh, not sure why nobody pointed to this yet.
In 2018, folks, here's how you can go about it:
async copySomething(text?) { try { const toCopy = text || location.href; await navigator.clipboard.writeText(toCopy); console.log('Text or Page URL copied'); } catch (err) { console.error('Failed to copy: ', err); } } UsedIt is used in my Angular 6+ code like so:
<button mat-menu-item (click)="copySomething()"> <span>Copy link</span> </button> If I pass in a string, it copies it. If nothing, it copies the page's URL.
More gymnastics to the clipboard stuff can be done too. See more infoinformation here:
https://developers.google.com/web/updates/2018/03/clipboardapiUnblocking Clipboard Access