Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "ng add" do in Angular CLI 6.0.8

Tags:

There doesn't appear to be any documentation for the ng add <collection> command for Angular 6. This appears to be a new feature, but I don't know what it does.

It's not listed on the official Wiki page:

https://github.com/angular/angular-cli/wiki

There is a child Wiki page for the command:

https://github.com/angular/angular-cli/wiki/add

But it says the same thing as the command line help.

Add support for a library to your project.

What library are they referring to? Is it a library like https://material.angular.io/ or is it something else?

like image 895
Reactgular Avatar asked Jun 29 '18 22:06

Reactgular


People also ask

What is Ng Add in angular?

ng add <collection> [options] Description. Adds the npm package for a published library to your workspace, and configures your default app project to use that library, in whatever way is specified by the library's schematic. For example, adding @angular/pwa configures your project for PWA support: ng add @angular/pwa.

What is the difference between NPM install and Ng add?

Whereas npm install <package> will only install your package into your project but will not configure in order to use. So, you mean a command like, ng add <package > will configure the package in angular-cli. json as well. Thank you so much for nice examples.

What is the use of NG new?

ng new also creates the following workspace and starter project files: A new workspace, with a root directory named angular-tour-of-heroes. An initial skeleton application project in the src/app subdirectory. Related configuration files.

What is NG new command?

ng new command creates a workspace of given name with a default Angular Application. It provides interactive prompts to set optional configurations. All prompts have default values to choose.


1 Answers

There's a good article available in the blog that explains this new feature

Another new CLI command ng add makes adding new capabilities to your project easy. ng add will use your package manager to download new dependencies and invoke an installation script (implemented as a schematic) which can update your project with configuration changes, add additional dependencies (e.g. polyfills), or scaffold package-specific initialization code.

Because ng add is built on top of schematics and the npm registry, our hope is that libraries and the community will help us build a rich ecosystem of ng add supporting packages.

Take a look at Angular Material’s ng-add schematic for an example to help you get started building your own ng-add schematics.

For example, the command can automatically update your app.module.ts and more to enable you to use the lib directly, without further hastle

like image 173
baao Avatar answered Oct 12 '22 08:10

baao