Angular Cheat Sheet

This is an ongoing cheat sheet I’m using for Angular. I’ll update it with more things as time goes on.
Have any good ones? Feel free to leave me a comment!

How to update your angular command line to the current latest version:

npm install --save-dev @angular/cli@latest

This updates both the global version that will be used when you create a new project, and the version you’re currently using in the project where you run this command.

To generate a new component via the command line:

ng generate component component_name

This will generate the component into the folder where you run the command from. This, by default, is usually the root folder.
If you want to generate the component into a separate folder, then make that folder first and navigate into it via the command line first.

To call a typescript function from Angular:


button (click)="test()" mat-button 

use (click)=”test()” to bind the click event to your typescript function. In this case, it will call the test() function when it’s clicked.
then in your .ts file, just create the funcion:

  test() {

To create a singleton service:

  ng g s services/api

This will create a singleton service called “api.service” in a folder called “services”.


Error: mat-form-field must contain a MatFormFieldControl.  
in unit tests?
Add MatInputModule to .spec.ts imports. 


Leave a comment

Your email address will not be published. Required fields are marked *