2016-12-19 84 views
5

如何更新Angular 2版本?我使用Angular CLI 1.0.0-beta.20-4,我嘗試了npm update --save,但它什麼也沒做。如何更新Angular CLI中的角度2

下面是目前我的package.json文件。感謝任何幫助。

{ 
    "name": "todo1", 
    "version": "0.0.0", 
    "license": "MIT", 
    "angular-cli": {}, 
    "scripts": { 
    "start": "ng serve", 
    "lint": "tslint \"src/**/*.ts\"", 
    "test": "ng test", 
    "pree2e": "webdriver-manager update", 
    "e2e": "protractor" 
    }, 
    "private": true, 
    "dependencies": { 
    "@angular/common": "2.2.1", 
    "@angular/compiler": "2.2.1", 
    "@angular/core": "2.2.1", 
    "@angular/forms": "2.2.1", 
    "@angular/http": "2.2.1", 
    "@angular/material": "^2.0.0-alpha.11-3", 
    "@angular/platform-browser": "2.2.1", 
    "@angular/platform-browser-dynamic": "2.2.1", 
    "@angular/router": "3.0.0", 
    "@types/hammerjs": "^2.0.33", 
    "@types/lodash": "^4.14.43", 
    "angular2-jwt": "^0.1.25", 
    "angular2-uuid": "^1.1.0", 
    "core-js": "^2.4.1", 
    "hammerjs": "^2.0.8", 
    "lodash": "^4.17.2", 
    "material-design-icons": "^3.0.1", 
    "rxjs": "5.0.0-beta.12", 
    "ts-helpers": "^1.1.1", 
    "zone.js": "^0.6.23" 
    }, 
    "devDependencies": { 
    "@types/hammerjs": "^2.0.33", 
    "@types/jasmine": "^2.2.30", 
    "angular-cli": "^1.0.0-beta.20-4", 
    "codelyzer": "~0.0.26", 
    "jasmine-core": "2.4.1", 
    "jasmine-spec-reporter": "2.5.0", 
    "karma": "1.2.0", 
    "karma-chrome-launcher": "^2.0.0", 
    "karma-cli": "^1.0.1", 
    "karma-jasmine": "^1.0.2", 
    "karma-remap-istanbul": "^0.2.1", 
    "protractor": "4.0.5", 
    "ts-node": "1.2.1", 
    "tslint": "3.13.0", 
    "typescript": "2.0.2" 
    } 
} 

回答

5

您可以更改@angular版本使用插入符號範圍,故宮將安裝最新的包到下一個主要版本。

"dependencies": { 
    "@angular/common": "^2.2.1", 
    "@angular/compiler": "^2.2.1", 
    "@angular/core": "^2.2.1", 
    "@angular/forms": "^2.2.1", 
    "@angular/http": "^2.2.1", 

此外,它會值得更新到最新的角度版本。有關說明,請參閱here

1

你在這裏的主要問題是,NPM更新將只更新到每個模塊的最新兼容版本與在指定的package.json最高版本的限制。

做到這一點,最安全的辦法是更新您的package.json有對未成年和接插部分通配符。 Angular 2(與角1相反)使用semVer(http://semver.org/),因此您可以安全地通配次要和補丁部分。

"@angular/common": "2.*.*", 
"@angular/compiler": "2.*.*", 
"@angular/core": "2.*.*", 
"@angular/forms": "2.*.*", 
"@angular/http": "2.*.*", 
"@angular/material": "^2.0.0-alpha.11-3", 
"@angular/platform-browser": "2.*.*", 
"@angular/platform-browser-dynamic": "2.*.*", 
"@angular/router": "3.0.0", 

運行NPM更新/ NPM重新安裝,你應該升級。