Angular clipboard CDK

Earlier, in our blog we have discussed about how to perform copy to clipboard feature in angular.

And also I have created a npm plugin for this feature.

Angular clipboard CDK

The Component Dev Kit (CDK) is a set of tools that implement common interaction patterns whilst being unopinionated about their presentation. It represents an abstraction of the core functionalities found in the Angular Material library, without any styling specific to Material Design. Think of the CDK as a blank state of well-tested functionality upon which you can develop your own bespoke components.

Definition from official website

The release candidate version of angular 9 brings separate module for clipboard feature.

In this post we will be using v/9.0.0-rc.8 to demonstrate the feature.

Step 1

Install the CDK package into the project.

npm i @angular/cdk@9.0.0-rc.8

Step 2

Import the ClipboardModule into target application module.

import { BrowserModule } from "@angular/platform-browser";
import { NgModule } from "@angular/core";
import { AppRoutingModule } from "./app-routing.module";
import { AppComponent } from "./app.component";
import { FormsModule } from "@angular/forms";
import { ClipboardModule } from "@angular/cdk/clipboard";
@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule,
   AppRoutingModule, 
   FormsModule, 
   ClipboardModule],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule {}

Step 3

Now use the cdkCopyToClipboard attribute and choose the content which needs to copied.

<div class="container">
	<h3>Clipboard demo</h3>
	<div>
		Copy the whole text inside the textarea
		<textarea rows="4" cols="50" [(ngModel)]="textValue"></textarea>
		<button cdkCopyToClipboard="{{textValue}}" class="waves-effect waves-light btn">
      Copy to clipboard
      </button>
	</div>
</div>

You can pass a static value or a variable to capture the dynamic value.

Demo

Happy Coding!

Funny Excuses that Devs Give

Devs are very brilliant and also they come up with super weird reasons when you catch a bug in their work. I’m a dev too and it was absolutely hilarious to see that I myself use the same excuses sometimes. I came across a meme and I forgot to screenshot it. I remember a few points from it. If you are a web dev, I’m sure you could relate to most of these excuses. Give it a read also a thumbs up if you could relate to any one of these points 🙂

  • It worked yesterday – Yeah, it was the compilers birthday yesterday and hence it compiled the code perfectly. Today it’s not in the mood to compile and hence it is throwing the error. Maybe you should try running the program when the compiler is in good mood.
  • Caching – Did you hard refresh? Did you clear your cache? I think the cache in your browser can’t be cleared, please use a different computer. Let me clean your cache, I’m an expert in clearing. I think the program is cached in the cloud, let me clear that as well.
  • That is weird! – Yes, that’s weird, you expected it to run, but when the QA runs it, it becomes weird. Guess your program is allergic to other people who wanted to see your code working.
  • How is that possible?? It never occurred to me – Exactly, How is that possible?
  • That is an issue with the 3rd party library that we are using – Lemme raise an issue in GitHub. Hopefully they will fix this issue within this year until then we’ll push this bug to the backlog.
  • What is the version of Chrome that you are using? Is it v79.0.3945.117? – No, It’s v79.0.3945.116. That’s exactly why you are getting this error. Could you please update your chrome?
  • I’ve not touched the code in weeks – Yeah, it could be some junior dev trying to figure out what exactly this piece of code does.
  • Did you restart your computer? – Bugs get accumulated if you don’t restart your computer everyday. So just restart and run the program. The error would be resolved (And most of the time it works!! Don’t know how.. )
  • Even-though it doesn’t work, how does the UI feel? – Like crap 🙂
  • The user wouldn’t do it that way – You QA people how do you find some creepy steps to reproduce the bug. Once I had a bug reported that occurs only when you perform certain steps after 37 seconds (seriously??).
  • This is very minor, the user wouldn’t even notice it – Absolutely yes, the user won’t notice if the login page doesn’t show up 🙂
  • Finally, the most used excuse – It works on my machine!! – Yeah, we’ll ship your machine along with the product so that there is no error thrown.

Those were the most common excuses that a dev would give to the QA or the manager. Hope that most of us would have used these or heard people using these. If yes, hit like, share it with your fellow colleagues who give excuses like these. For more tech related posts follow this blog. This is SamuelLawrentz, do connect with me on LinkedIn for more updates.

Happy Coding!