How to Create a specific version of Angular Projec

2019-05-02 23:12发布

问题:

Actually, my npm version is 5.5.1 and angular cli version is 6.2.1. When I try to create a new project using the command ng new Project_name then it is creating the latest version of angular (in my case it is creating Angular version ^6.1.0). But I want Angular4. My question is how to create this Angualr2/4/5 (specific version instead of the latest version)? I don't think to change the version value in package.json will help in my case because there are some differences in the older versions and the latest 6 version (like the name of one file changed from angular-cli.json to anguar.json and not only name but content also changed.) I've also raised the same question in Angular-cli Github site as well. click here

Thanks in advance!!strong text

回答1:

Using CLI you can not create specific angular version.

But you can install angular into particular project.

For Example :

First create new folder inside any drive. Ex: d:\projects\demo.

Then find this folder inside Command Prompt(cmd). and

Run command : npm install @angular/cli@1.7.x for angular 5. and use similar command for other version.

After that just create project inside d:\projects\demo\ folder using the command ng new Project_name and it will create angular 5 Project.



回答2:

Create a package.json file then define the angular version you want to install then run npm install it will create project in the required version irrespective of the global angular cli



回答3:

this should work Use a package called npx npm i -g npx and when you need to create an angular project use this command the first time npx -p @angular/cli ng new hello-world-project after that you can use normal commands to work like ng g c abc