What’s new in ANGULAR 6?

Table of contents
Reading Time: 3 minutes

Angular has just released its v6. This major release focuses mainly on the toolchain and making easier for the user to create an application.

angular

As part of this release, a new version has updated core framework packages (@angular/core, @angular/common & @angular/compiler etc), the Angular CLI, and Angular Material + CDK.  You can see the changelog here frameworkmaterial+cdkcli.

In this blog, I am going to explain some major changes that make building process much easier.

1. ng update
ng update  is the new CLI command that will analyze your package.json and gives you a recommendation regarding updation of the packages for your application.

ng update will help you adopt the right version of dependencies, and keep our dependencies in sync. If one of our dependencies provides ng updateschematic, they will automatically make changes to the code to keep our code updated.

2. ng add
This is an another new CLI command. ng add will help to download new dependencies/package and run an installation script which can update our project with configuration changes. It has added new capabilities to your application.

3. CLI + Material Starter Templates.
The next addition is angular material starter templates with angular CLI. Now once you run ng g @angular/material to add material to your existing application you will also be able to generate three new starter templates like :

a.) Material Sidenav
It will generate a starter component with sidebar navigation.

1_PKi-6dOhlb61g8CM2JCx-Q

ng generate @angular/material:material-nav --name=my-nav

b.) Material Dashboard.
It will generate a starter component containing dynamic grid list of cards.

1_De1Vnm2m1yID_EL_xRYIyw

ng generate @angular/material:material-dashboard --name=my-dashboard

c.) Material Data Table
It will generate data table component that is pre-configured for sorting and pagination.

1_2MO1hno7d30iTPIZ9CnBzw

ng generate @angular/material:material-table --name=my-table

4. Registering Providers.
That’s a very cool feature!

Earlier if we had a service, to make use of it we were supposed to register it with the injector in a particular module, we used to import it and add it to the provider’s array but now we can do it in the service itself. A way to do that is to use providedIn property in the injectable decorator. ProvidedIn tells us about the root module which is responsible for creating an instance of the services. By this way, services will be available to an entire application.

BEFORE

// App.module.ts
@NgModule({
  ...
  providers: [MyService]
})
export class AppModule {}
//myservice.service.ts
import { Injectable } from '@angular/core';

@Injectable()
export class MyService {
  constructor() { }
}

AFTER

//myservice.service.ts
import { Injectable } from '@angular/core';

@Injectable({
  providedIn: 'root',
})
export class MyService {
  constructor() { }
}

5. RxJS V6
Angular has been updated to use v6 of RxJS. RxJS is an independent open source project that released v6 several weeks ago. RxJS v6 comes with several major changes along with a backward compatibility package rxjs-compat that will keep your application working.

6. Angular CLI
CLI v6 now has support for workspaces containing multiple projects or libraries. CLI projects will have angular.json instead of .angular-cli.json for configuration. Each CLI workspace has projects, each project has targets, and each target can have configurations.

Angular has increased the speed and decreased the boilerplate code. There are many other cool features angular has provided. You can check it here.

Thanks for reading. Happy Blogging!

knoldus-advt-sticker

Written by 

Aakash Jain is a software consultant having more than 1 year of experience. Aakash likes to explore new technologies. He loves online gaming, watching marvels movies, playing badminton and exploring new places. Aakash is familiar with programming languages such as Angular 4, Java, Scala, C++, TypeScript, HTML and CSS.

1 thought on “What’s new in ANGULAR 6?3 min read

Comments are closed.

Discover more from Knoldus Blogs

Subscribe now to keep reading and get access to the full archive.

Continue reading