首先从您的 cli 安装最新版本。然后在 package.json 的“依赖项”部分中指定您想要的版本。例如,如果你想要Angular 4.3.4,那么你可以编辑你的 package.json 文件,比如
"dependencies": {
"@angular/animations": "^4.3.4",
"@angular/common": "^4.3.4",
"@angular/compiler": "^4.3.4",
"@angular/core": "^4.3.4",
"@angular/forms": "^4.3.4",
"@angular/http": "^4.3.4",
"@angular/platform-browser": "^4.3.4",
"@angular/platform-browser-dynamic": "^4.3.4",
"@angular/router": "^4.3.4",
...........................
...........................
}
同时更改你的 devDependencies
"devDependencies": {
"@angular/compiler-cli": "^4.3.4",
"@angular/language-service": "^4.3.4",
.............
}
现在运行npm install
npm install
完成安装后,您应该可以通过ng -v 命令看到您的版本,如下所示
Angular CLI: 1.6.3
Node: 9.3.0
OS: linux x64
Angular: 4.4.6
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router, tsc-wrapped
@angular/cli: 1.6.3
@angular-devkit/build-optimizer: 0.0.38
@angular-devkit/core: 0.0.25
@angular-devkit/schematics: 0.0.48
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.9.3
@schematics/angular: 0.1.13
@schematics/schematics: 0.0.13
typescript: 2.4.2
webpack: 3.10.0
PS:从您的问题中,您提到npm install -g @angular/cli@1.4 在您尝试安装 angular 4
时没有 1.4 版本