Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between ng add <package name> vs npm install <package name> in angular 6

As Angular6 has been released, They have added a new command ng add . Can anyone tell me what will be the difference between existing command npm install <package> and ng add <package>

like image 346
Nimish goel Avatar asked May 04 '18 07:05

Nimish goel


People also ask

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.

What is the difference between Ng and npm?

NPM is basically a package manager which acts as a dependency provider. If there are many small packages, required to build a large one, NPM is the one hotspot which will provide us with the packages. Angular-CLI is one of those packages. As far as NG is concerned, it is the core module of Angular.

What is Ng Add in Angular?

ng add will use our package manager to download new dependencies and invoke an installation script (implemented as a schematic) which can update our Angular project with configuration changes and adds additional dependencies like polyfills, or scaffold package-specific initialization code.

What is npm install in Angular?

The Angular Framework, Angular CLI, and components used by Angular applications are packaged as npm packages and distributed using the npm registry. You can download and install these npm packages by using the npm CLI client, which is installed with and runs as a Node. js® application.


2 Answers

ng add

ng add <package> uses your package manager and installs the dependency. That dependency can have an installation script which can be used to do more job except the dependency installation. It can update your configurations, download another dependencies based on that one or create scaffold templates (with initial markup and logic).

To use ng add for a third party dependency, that team must provide schematics which describes the installation script. This can include some .scss or .css or related .js files to be included in the angular.json file.

In your provided link, you can install material package and also create some components with components

npm install

npm install <package> just installs the dependency.

For more Version 6 of Angular Now Available.

like image 157
Suren Srapyan Avatar answered Sep 30 '22 15:09

Suren Srapyan


ng add

Will use your package manager to download new dependencies and invoke an installation script which can update your project with configuration changes (In angular.json file as well), add additional dependencies (e.g. polyfills if needed), or scaffold package-specific initialization code.

For example you run the command ng add @angular/material — Install, it will automatically install the package and configure in angular.json file too.

npm install

Whereas npm install <package> will only install your package into your project but will not configure in order to use.

For example you run the command npm install jquery it will install jQuery in your project but you need to configure manually in .angular-cli.json file (as in v5)

For more information read out here -

  • https://blog.angular.io/version-6-of-angular-now-available-cc56b0efa7a4
like image 35
Pardeep Jain Avatar answered Sep 30 '22 15:09

Pardeep Jain