How to update angular 2 in angular CLI

How to upgrade version of Angular 2? I am using Angular CLI 1.0.0-beta.20-4 and I tried updating npm --save, but it does nothing.

Below is my package.json file at the moment. Appreciate any help on this.

{ "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
source share
2 answers

You can change @ angular versions to use a carriage range so that NPM installs the latest package before the next major version.

  "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", 

It would also be useful to upgrade to the latest version of angular-cli. See here for more details.

+5
source

The main problem that you are facing is that the npm update will only be updated to the latest compatible version of each module with the restriction of the highest version specified in package.json.

The safest way to do this is to upgrade your .json package to have a wildcard for junior and patch sections. Angular 2 (unlike Angular 1) uses semVer ( http://semver.org/ ), so you can safely substitute minor and patch parts.

 "@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", 

Run the npm / npm update and you should update it.

+1
source

Source: https://habr.com/ru/post/1261497/


All Articles