问题
I have recently installed Angular 6 and would like to go back to using Angular 5.2 How can I change my Angular version from whatever version I have to whichever one I choose?
Answer: The version of angular used in a project is determined by the version of angular cli installed. any specific version of angular cli can be installed with the following command:
npm install --global @angular/cli@x.x.x
.
example:
npm install --global @angular/cli@1.6.6
even if you have another version of angular cli (either newer or older) installed that won't cause issues.
回答1:
First you need to uninstall, install the cli
npm uninstall -g angular-cli
npm cache clean
npm install -g angular-cli@1.6.1
After this, delete node_modules directory
Then change your package versions in package.json
to have versions like the following
{
...
},
...
"dependencies": {
"@angular/animations": "5.2.2",
"@angular/cdk": "^5.2.2",
"@angular/common": "5.2.2",
"@angular/compiler": "5.2.2",
"@angular/core": "5.2.2",
"@angular/forms": "5.2.2",
"@angular/http": "5.2.2",
"@angular/material": "^5.2.2",
"@angular/platform-browser": "5.2.2",
"@angular/platform-browser-dynamic": "5.2.2",
"@angular/router": "5.2.2",
"@ngrx/core": "^1.2.0",
"@ngrx/store": "^4.0.3",
"core-js": "^2.5.1",
"hammerjs": "^2.0.8",
"rxjs": "^5.5.2",
"typescript": "^2.4.2",
"web-animations-js": "^2.3.1",
"zone.js": "^0.8.18"
},
"devDependencies": {
"@angular/cli": "1.6.1",
"@angular/compiler-cli": "5.2.2",
"@angular/language-service": "5.2.2",
"@types/jasmine": "~2.5.53",
"@types/jasminewd2": "~2.0.2",
"@types/node": "~6.0.60",
...
}
}
and install packages
npm install
回答2:
I will try to give a general answer for futere similar issues.
The version of angular used in a project is determined by the version of angular cli installed. any specific version of angular cli can be installed with the following command:
npm install --global @angular/cli@x.x.x.
example:
npm install --global @angular/cli@1.6.6
even if you have another version of angular cli (either newer or older) installed. That should not cause issues. however to be sure you can use:
npm uninstall -g angular-cli
npm cache clean
npm install -g angular-cli@1.6.1
来源:https://stackoverflow.com/questions/50415235/how-to-change-upgrade-or-downgrade-angular-version