我刚开始学习Angular,我下载了最新版本的node js并安装了angular cli。然后我开始研究一个项目,发现我需要Angular 4,而我开始使用Angular 5
"dependencies": {
"@angular/animations": "^5.0.0",
"@angular/common": "^5.0.0",
"@angular/compiler": "^5.0.0",
"@angular/core": "^5.0.0",
"@angular/forms": "^5.0.0",
"@angular/http": "^5.0.0",
"@angular/platform-browser": "^5.0.0",
"@angular/platform-browser-dynamic": "^5.0.0",
"@angular/router": "^5.0.0",
"bootstrap": "^3.3.7",
"core-js": "^2.4.1",
"rxjs": "^5.5.2",
"zone.js": "^0.8.14"
},
有没有办法在不重新启动项目的情况下迁移回来?有没有办法指定在使用ng new
创建项目时使用哪个版本的Angular?
答案 0 :(得分:2)
你为什么要降级?您的项目是全新的,为什么不使用最新版本?
如果您想降级,只需将package.json
中的版本替换为您想要的版本即可。
这看起来像
"dependencies": {
"@angular/animations": "^4.3.1",
"@angular/common": "^4.3.1",
"@angular/compiler": "^4.3.1",
"@angular/core": "^4.3.1",
"@angular/forms": "^4.3.1",
"@angular/http": "^4.3.1",
"@angular/platform-browser": "^4.3.1",
"@angular/platform-browser-dynamic": "^4.3.1",
"@angular/router": "^4.3.1",
"bootstrap": "^3.3.7",
"core-js": "^2.4.1",
"rxjs": "^5.5.2",
"zone.js": "^0.8.14"
},
只需保留miind,您还需要设置所有依赖项的版本,但您的控制台会告诉您,不要担心。
答案 1 :(得分:2)
对package.json使用以下代码:
"dependencies": {
"@angular/animations": "^4.4.6",
"@angular/common": "^4.4.6",
"@angular/compiler": "^4.4.6",
"@angular/core": "^4.4.6",
"@angular/forms": "^4.4.6",
"@angular/http": "^4.4.6",
"@angular/platform-browser": "^4.4.6",
"@angular/platform-browser-dynamic": "^4.4.6",
"@angular/router": "^4.4.6",
"rxjs": "^5.4.2"
},
"devDependencies": {
"@angular/cli": "1.4.9",
"@angular/compiler-cli": "^4.4.6",
}
在terminal / command-prompt上运行npm install并运行您的项目。现在你正在运行angular 4项目。 希望它会有所帮助。