Angular Cli Commands Cheat Sheet



Cheat Sheet for Mermaid. Gantt dateFormat YYYY-MM-DD title Adding GANTT diagram functionality to mermaid section A section Completed task:done, des1, 2018-01-08 Active task:active, des2, 2018-01-09, 3d Future task: des3, after des2, 5d Future task2: des4, after des3, 5d section Critical tasks Completed task in the critical line:crit, done, 2018-01-06,24h Implement parser. In laravel, an artisan console command-line is a tool to run Laravel commands. If you use these commands, it improves the development speed by providing ready to use scaffolding and required methods. Angular CLI Cheat Sheet: The best Commands to boost your productivity. How to use Routing in Angular. August 11, 2017. Angular Universal and Server. You can follow this angular cheat sheet to build your project. We have tried to cover Angular CLI, Angular Lifecycle Hooks, Angular Routing and much more here. Angular gives us the ability to do a whole lot using their CLI. You can config the entire application by just using the CLI. Here are some of the commands.

In this post I give an overview of the most uses Angular CLI command. Using the CLI commands can greatly boost your productivity on Angular projects. Create a new app Create a new angular application with the default styling option CSS. Ng new app-name Create new angular project with scss styling and a routing module.

Angular is a popular JavaScript library developed by Google for building web application user interfaces. The Visual Studio Code editor supports Angular IntelliSense and code navigation out of the box.

Welcome to Angular

We'll be using the Angular CLI for this tutorial. To install and use the command line interface as well as run the Angular application server, you'll need the Node.js JavaScript runtime and npm (the Node.js package manager) installed. npm is included with Node.js which you can install from Node.js downloads.

Tip: To test that you have Node.js and npm correctly installed on your machine, you can type node --version and npm --version.

To install the Angular CLI, in a terminal or command prompt type:

This may take a few minutes to install. You can now create a new Angular application by typing:

my-app is the name of the folder for your application. This may take a few minutes to create the Angular application in TypeScript and install its dependencies.

Let's quickly run our Angular application by navigating to the new folder and typing ng serve to start the web server and open the application in a browser:

You should see 'Welcome to app!!' on http://localhost:4200 in your browser. We'll leave the web server running while we look at the application with VS Code.

To open your Angular application in VS Code, open another terminal (or command prompt) and navigate to the my-app folder and type code .:

Syntax highlighting and bracket matching

Now expand the srcapp folder and select the app.component.ts file. You'll notice that VS Code has syntax highlighting for the various source code elements and, if you put the cursor on a parenthesis, the matching bracket is also selected.

IntelliSense

Ng command listAngular cli commands cheat sheet pdf

As you hover your mouse over text in the file, you'll see that VS Code gives you information about key items in your source code. Items such as variables, classes and Angular decorators are a few examples where you'll be presented with this information.

As you start typing in app.component.ts, you'll see smart suggestions and code snippets.

You can click the information button (i) to see a flyout with more documentation.

VS Code uses the TypeScript language service for code intelligence (IntelliSense) and it has a feature called Automatic Type Acquisition (ATA). ATA pulls down the npm Type Declaration files (*.d.ts) for the npm modules referenced in the package.json.

Go to Definition, Peek definition

Through the TypeScript language service, VS Code can also provide type definition information in the editor through Go to Definition (F12) or Peek Definition (⌥F12 (Windows Alt+F12, Linux Ctrl+Shift+F10)). Open the app.module.ts file and put the cursor over AppComponent in the bootstrap property declaration, right click and select Peek Definition. A Peek window will open showing the AppComponent definition from app.component.ts.

Press Escape to close the Peek window.

Hello World!

Let's update the sample application to 'Hello World'. Go back to the app.component.ts file and change the title string in AppComponent to 'Hello World'.

Once you save the app.component.ts file, the running instance of the server will update the web page and you'll see 'Welcome to Hello World!!'.

Tip: VS Code supports Auto Save, which by default saves your files after a delay. Check the Auto Save option in the File menu to turn on Auto Save or directly configure the files.autoSave user setting.

Debugging Angular

To debug the client side Angular code, we'll need to install the Debugger for Chrome extension.

Note: This tutorial assumes you have the Chrome browser installed. There are also debugger extensions for the Edge and Firefox browsers.

Open the Extensions view (⇧⌘X (Windows, Linux Ctrl+Shift+X)) and type 'chrome' in the search box. You'll see several extensions which reference Chrome.

Press the Install button for Debugger for Chrome.

Set a breakpoint

To set a breakpoint in app.component.ts, click on the gutter to the left of the line numbers. This will set a breakpoint which will be visible as a red circle.

Configure the Chrome debugger

We need to initially configure the debugger. To do so, go to the Run view (⇧⌘D (Windows, Linux Ctrl+Shift+D)) and click on the gear button to create a launch.json debugger configuration file. Choose Chrome from the Select Environment dropdown list. This will create a launch.json file in a new .vscode folder in your project which includes a configuration to launch the website.

We need to make one change for our example: change the port of the url from 8080 to 4200. Your launch.json should look like this:

Press F5 or the green arrow to launch the debugger and open a new browser instance. The source code where the breakpoint is set runs on startup before the debugger was attached so we won't hit the breakpoint until we refresh the web page. Refresh the page and you should hit your breakpoint.

You can step through your source code (F10), inspect variables such as AppComponent, and see the call stack of the client side Angular application.

The Debugger for Chrome extension README has lots of information on other configurations, working with sourcemaps, and troubleshooting. You can review it directly within VS Code from the Extensions view by clicking on the extension item and opening the Details view.

Popular Starter Kits

In this tutorial, we used the Angular CLI to create a simple Angular application. There are lots of great samples and starter kits available to help build your first Angular application.

Recipes

The VS Code team has created recipes for more complex debugging scenarios. There you'll find the Chrome Debugging with Angular CLI recipe which also uses the Angular CLI and goes into detail on debugging the generated project's unit tests.

MEAN Starter

If you'd like to see a full MEAN (MongoDB, Express, Angular, Node.js) stack example, look at MEAN.JS. They have documentation and an application generator for a sample MEAN project. You'll need to install and start MongoDB, but you'll quickly have a MEAN application running. VS Code also has great MongoDB support through the Azure Databases extension.

React

React is another popular web framework. If you'd like to see an example of React working with VS Code, check out the Using React in VS Code tutorial. It will walk you through creating an React application and configuring the launch.json file for the Debugger for Chrome extension.

Angular Extensions

In addition to the functionality, VS Code provides out of the box, you can install VS Code extensions for greater functionality.

Click on an extension tile above to read the description and reviews on the Marketplace.

To find other Angular extensions, open the Extensions view (⇧⌘X (Windows, Linux Ctrl+Shift+X)) and type 'angular' to see a filtered list of Angular extensions.

The community has also created 'Extension Packs' which bundle useful extensions together (for example, a linter, debugger, and snippets) into a single download. To see available Angular extension packs, add the 'extension packs' category to your filter (angular @category:'extension packs').

3/31/2021

Angular

Angular is a leading, powerful and most popular frontend javascript framework for creating single page application or SPA. With angular we can create mobile application, desktop applicaion as well as web application very quickly and easily. Angular is much faster and easier than its previous version angular js. Unlike angular js, angular is written in typescript.

Cli
VersionReleased Date
Angular 2Released on September 14th, 2016
Angular 3Not released for public, due to misalignment of router package
Angular 4Released on November 1st, 2017
Angular 5Released on November 1st, 2017
Angular 6Released on May 4th, 2018
Angular 7Released on October 18th, 2018
Angular 8Released on May 28th, 2019
Angular 9Released on February 7th, 2020
Angular 10Released on June 24th, 2020
Angular 11Released on November 11, 2020
Angular 12Next

Benefits of Angular

  • Angular is a component based framework which gives a clean structure for our application.
  • It has declarative templates which includes lots of reusable code.
  • Angular is developed using TypeScript, but we can write our code in either JavaScript or TypeScript.
  • Angular code is more testable code, which supports to build lots of automated test.

Angular CLI

The Angular CLI is a command-line interface tool that will help us to initialize, develop, scaffold, and maintain Angular applications. We can use this tool directly in a terminal, or indirectly through an interactive UI such as Angular Console. We can create Angular applications using Angular CLI by following below steps-

Angular Cheat Sheet Pdf

Step 1:- To start with creating Angular CLI application we first need to install NodeJS.

Step 2:- Install Angular CLI by running below command-

Step 3:- Now, to create angular applicaion, just run below command-

Ng Serve Command

Our newly created app will look like below:-

Some important CLI command:-

CommandAliaaDescription
add-It adds support for an external library to our Angular CLI project.
buildbIt compiles an Angular application into an output directory named 'dist' at the given output path.
configbIt retrieves or sets Angular application configuration values in the angular.json file for the workspace.
docdIt opens the official Angular documentation (i.e. angular.io) in a browser, and searches for a given keyword.
e2eeIt builds and serves an Angular application, then runs end-to-end tests using Protractor.
generategIt will generate and/or modifies files based on a schematic.
help-It will provide a list of available angular CLI commands and their short descriptions.
lintlIt will run linting tools on our Angular app code in a given project folder.
newnIt will create a new workspace and an initial or starter Angular application.
run-It will run an architect target with an optional custom builder configuration defined in our angular project.
servesIt builds and serves our angular application. It also rebuilds on file changes.
testtIt will run unit tests in our angular project.
update-It updates our angular application and its dependencies.
versionvTo see angular CLI version.
xi18n-It will extracts i18n messages from source code.