Getting Started With Angular 7.0

Introduction

Angular has released its latest version, Angular 7.0. In this article, we will explore the following points -
  • What is new in Angular 7.0?
  • Creating the first Angular 7.0 application using Angular CLI.
  • How to update existing Angular application to Angular 7.0?
What’s new in Angular 7.0?
  • While creating a new Angular application, the Angular CLI will prompt the user to select if they want to add features like Angular routing or the format of stylesheet they want to use in their application.

  • Angular 7.0 application will use the Bundle Budget feature of Angular CLI to warn the developers if the application bundle size exceeds the predefined limit. The default the value for a warning is set to 2MB and for error, it is 5MB. This value is configurable and can be changed from the angular.json file. This feature enhances the application performance considerably.

  • The Component Dev Kit (CDK) of Angular Material also receives some new features as part of this update. The two newly added feature of CDK is mentioned below:
Virtual Scrolling
 
If you are trying to load a large list of elements then it can affect the application performance. The <cdk-virtual-scroll-viewport> tag can be used to load only the visible part of the list on the screen. It will render only the items that can fit on the screen. When a user scrolls through the list, the DOM will load and unload the elements dynamically based on the display size. This feature is not to be confused with infinite scrolling which is altogether a different strategy to load elements. You can read more about Virtual Scrolling here.
 
Drag and Drop
 
We can easily add drag and drop feature to an item. It supports features such free dragging of an element, reordering items of a list, moving items between list, animation, adding custom drag handle and restricted dragging along X or Y axis. You can read more about Drag and Drop here.
  • The mat-form-field will now support the use of the native select element. This will provide an enhanced performance and usability to the application. 

  • Angular 7.0 has updated its dependencies to support Typescript 3.1, RxJS 6.3 and Node 10.
We will proceed to create our first Angular 7 application.
 
Prerequisites
  • Install the latest version of Node.js from here
  • Install Visual Studio Code from here
Installing node.js will also install npm on your machine. After installing Node.js, open the command prompt and run the following set of commands to check the version of node and npm installed on your machine.
  • node -v
  • npm -v
Refer to the image below.

 
 
Installing Angular CLI
 
Angular CLI is the Command Line interface for Angular. It helps us to initialize, develop and maintain Angular applications easily.
 
To install Angular CLI, run the following command in the command window,
  • npm i -g @angular/cli
This will install Angular CLI 7.0 globally in your machine. Refer to the image below.
 
 
 
To check the version of Angular CLI installed on your machine, run following command.
  • ng version
Refer to the image below.
 
 
 
Create the Angular 7 app
 
Open Visual Studio Code and navigate to View >> Terminal. This will open the VS Code terminal window. Alternatively, you can also use the keyboard shortcut ctrl+` to open the terminal window.
 
Type the following sequence of commands in the terminal window. These commands will create a directory with name “ng7Demo” and then create an Angular application with the name “ng7App” inside that directory.
  • mkdir ng7Demo
  • cd ng7Demo
  • ng new ng7App
As you run the ng new command, the Angular CLI will ask you to select the following two option,
  1. Would you like to add Angular routing? (y/N)
  2. Which stylesheet format would you like to use?
Select the desired option and hit enter to create the Angular 7.0 application. Refer to the below Gif image for better understanding.
 
 
 
Once the application creation is successful, run the following command to open the project.
  • code .
Refer to the image below,
 
 
This will open the code file of our application in a new VS Code window. You can see the following file structure in Solution Explorer.
 
 
 
Open the package.json file and you can observe that we have the latest Angular 7.0.0 packages installed in our project.
  1. {  
  2.   "name""ng7-app",  
  3.   "version""0.0.0",  
  4.   "scripts": {  
  5.     "ng""ng",  
  6.     "start""ng serve",  
  7.     "build""ng build",  
  8.     "test""ng test",  
  9.     "lint""ng lint",  
  10.     "e2e""ng e2e"  
  11.   },  
  12.   "private"true,  
  13.   "dependencies": {  
  14.     "@angular/animations""~7.0.0",  
  15.     "@angular/common""~7.0.0",  
  16.     "@angular/compiler""~7.0.0",  
  17.     "@angular/core""~7.0.0",  
  18.     "@angular/forms""~7.0.0",  
  19.     "@angular/http""~7.0.0",  
  20.     "@angular/platform-browser""~7.0.0",  
  21.     "@angular/platform-browser-dynamic""~7.0.0",  
  22.     "@angular/router""~7.0.0",  
  23.     "core-js""^2.5.4",  
  24.     "rxjs""~6.3.3",  
  25.     "zone.js""~0.8.26"  
  26.   },  
  27.   "devDependencies": {  
  28.     "@angular-devkit/build-angular""~0.10.0",  
  29.     "@angular/cli""~7.0.1",  
  30.     "@angular/compiler-cli""~7.0.0",  
  31.     "@angular/language-service""~7.0.0",  
  32.     "@types/node""~8.9.4",  
  33.     "@types/jasmine""~2.8.8",  
  34.     "@types/jasminewd2""~2.0.3",  
  35.     "codelyzer""~4.5.0",  
  36.     "jasmine-core""~2.99.1",  
  37.     "jasmine-spec-reporter""~4.2.1",  
  38.     "karma""~3.0.0",  
  39.     "karma-chrome-launcher""~2.2.0",  
  40.     "karma-coverage-istanbul-reporter""~2.0.1",  
  41.     "karma-jasmine""~1.1.2",  
  42.     "karma-jasmine-html-reporter""^0.2.2",  
  43.     "protractor""~5.4.0",  
  44.     "ts-node""~7.0.0",  
  45.     "tslint""~5.11.0",  
  46.     "typescript""~3.1.1"  
  47.   }  
  48. }   
Execution Demo
 
The name of our Angular application is ng7App which is inside ng7Demo directory. So, we will first navigate to our application using the below commands.
  • cd ng7Demo
  • cd ng7App 
Now, we use the following command to start the web server.
  • ng serve 
Refer to the image below,
 
 
 
After running this command, you can see that it is asking to open http://localhost:4200 in your browser. So, open any browser on your machine and navigate to this URL. Now, you can see the output screen as shown below.
 
 
 
How to upgrade to Angular 7?
 
The Angular team has provided an Angular Update Guide to ensure smooth upgrade of Angular versions. Navigate to https://update.angular.io/. You will see the page as shown below,
 
 
 
It is self-explanatory and easy to use application. It will show you the steps that you need to follow before updating, during the update and after the update.
 
If you want to update your application from Angular 6 to Angular 7 then run the following command in the project folder.
  • ng update @angular/cli @angular/core
Conclusion 
 
We have learned about the new features of Angular 7.0. We also installed Angular CLI 7.0. To create and execute Angular 7.0 app we have used Angular CLI and VS Code. We also explored the method to upgrade an existing application to Angular 7.0.