更新到 Angular 5
Update to Angular 5
如何更新到Angular5?
这是来自我的 package.json:
"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",
"@types/jwt-decode": "^2.2.1",
"bootstrap": "^3.3.7",
"bootstrap-sass": "^3.3.7",
"classlist.js": "^1.1.20150312",
"core-js": "^2.4.1",
"intl": "^1.2.5",
"jquery": "^3.2.1",
"jwt-decode": "^2.2.0",
"rxjs": "^5.4.2",
"zone.js": "^0.8.14"
},
"devDependencies": {
"@angular/cli": "1.4.0-rc.2",
"@angular/compiler-cli": "5.0.0",
"@angular/language-service": "5.0.0",
"@types/jasmine": "~2.5.53",
"@types/jasminewd2": "~2.0.2",
"@types/node": "~6.0.60",
"angular-ide": "^0.9.31",
"codelyzer": "~3.1.1",
"jasmine-core": "~2.6.2",
"jasmine-spec-reporter": "~4.1.0",
"karma": "~1.7.0",
"karma-chrome-launcher": "~2.1.1",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"node-sass": "^4.5.3",
"protractor": "~5.1.2",
"raw-loader": "^0.5.1",
"sass-loader": "^6.0.6",
"sw-precache": "^5.2.0",
"ts-node": "~3.2.0",
"tslint": "~5.3.2",
"typescript": "~2.3.3"
}
当我 运行 npm install 我得到这个错误
npm ERR! Windows_NT 6.1.7601 npm ERR! argv "C:\Program
Files\nodejs\node.exe" "C:\Program
Files\nodejs\node_modules\npm\bin\npm-cli.js" "install" npm ERR!
node v6.11.2 npm ERR! npm v3.10.10 npm ERR! code ETARGET
npm ERR! notarget No compatible version found: @angular/common@5.0.0
npm ERR! notarget Valid install targets: npm ERR! notarget 5.0.0-rc.0,
5.0.0-beta.7, 5.0.0-beta.6, 5.0.0-beta.5, 5.0.0-beta.4, 5.0.0-beta.3, 5.0.0-beta.2, 5.0.0-beta.1, 5.0.0-beta.0, 4.4.4, 4.4.3, 4.4.2,
4.4.1, 4.4.0-RC.0, 4.3.6, 4.3.5, 4.3.4, 4.3.3, 4.3.2, 4.3.1, 4.3.0, 4.3.0-rc.0, 4.3.0-beta.1, 4.3.0-beta.0, 4.2.6, 4.2.5, 4.2.4, 4.2.3, 4.2.2, 4.2.1, 4.2.0, 4.2. 0-rc.2, 4.2.0-rc.1, 4.2.0-rc.0, 4.2.0-beta.1, 4.2.0-beta.0, 4.1.3, 4.1.2, 4.1.1, 4.1.0, 4.1.0-rc.0, 4.1.0-beta.1, 4.1.0-beta.0, 4.0.3, 4.0.2, 4.0.1, 4.0.0, 4.0.0- rc.6, 4.0.0-rc.5, 4.0.0-rc.4, 4.0.0-rc.3, 4.0.0-rc.2, 4.0.0-rc.1, 4.0.0-rc.0, 4.0.0-beta.8, 4.0.0-beta.7, 4.0.0-beta.6, 4.0.0-beta.5, 4.0.0-beta.4, 4.0.0-beta.3,
4.0.0-beta.2, 4.0.0-beta.1, 4.0.0-beta.0, 2.4.10, 2.4.9, 2.4.8, 2.4.7, 2.4.6, 2.4.5, 2.4.4, 2.4.3, 2.4.2, 2.4.1, 2.4.0, 2.3.1, 2.3.0, 2.3.0-rc.0, 2.3.0-beta.1, 2.
3.0-beta.0, 2.2.4, 2.2.3, 2.2.2, 2.2.1, 2.2.0, 2.2.0-rc.0, 2.2.0-beta.1, 2.2.0-beta.0, 2.1.2, 2.1.1, 2.1.0, 2.1.0-rc.0, 2.1.0-beta.0, 2.0.2, 2.0.1, 2.0.0, 2.0.0-r c.7, 2.0.0-rc.6, 2.0.0-rc.5, 2.0.0-rc.4, 2.0.0-rc.3, 2.0.0-rc.2, 2.0.0-rc.1, 2.0.0-rc.0, 0.0.0-7, 0.0.0-6, 0.0.0-5, 0.0.0-4, 0.0.0-3, 0.0.0-2, 0.0.0-1, 0.0.0-0 npm ERR! notarget npm ERR! notarget This is most likely not a problem with npm itself. npm ERR! notarget In most cases
you or one of your dependencies are requesting npm ERR! notarget a
package version that doesn't exist. npm ERR! notarget npm ERR!
notarget It was specified as a dependency of 'gizza' npm ERR! notarget
我知道 Angular 5 仍处于测试阶段,但我想测试它。
编辑:截至 2017 年 11 月 1 日,版本 5.0.0 现已存在
编辑:版本 5.0.0 现在确实存在于 2017 年 11 月 1 日
NPM 告诉您 5.0.0 不存在。将您的 package.json 更改为建议的候选版本之一,例如 5.0.0-rc.0。很有可能它们也不完全一样,所以请阅读 npm 错误,它在这种情况下实际上很有帮助。
"dependencies": {
"@angular/animations": "5.0.0-rc.0",
"@angular/common": "5.0.0-rc.0",
"@angular/compiler": "5.0.0-rc.0",
"@angular/core": "5.0.0-rc.0",
"@angular/forms": "5.0.0-rc.0",
"@angular/http": "5.0.0-rc.0",
"@angular/platform-browser": "5.0.0-rc.0",
"@angular/platform-browser-dynamic": "5.0.0-rc.0",
"@angular/router": "5.0.0-rc.0",
"@types/jwt-decode": "^2.2.1",
"bootstrap": "^3.3.7",
"bootstrap-sass": "^3.3.7",
"classlist.js": "^1.1.20150312",
"core-js": "^2.4.1",
"intl": "^1.2.5",
"jquery": "^3.2.1",
"jwt-decode": "^2.2.0",
"rxjs": "^5.4.2",
"zone.js": "^0.8.14"
},
"devDependencies": {
"@angular/cli": "1.4.0-rc.2",
"@angular/compiler-cli": "5.0.0",
"@angular/language-service": "5.0.0",
"@types/jasmine": "~2.5.53",
"@types/jasminewd2": "~2.0.2",
"@types/node": "~6.0.60",
"angular-ide": "^0.9.31",
"codelyzer": "~3.1.1",
"jasmine-core": "~2.6.2",
"jasmine-spec-reporter": "~4.1.0",
"karma": "~1.7.0",
"karma-chrome-launcher": "~2.1.1",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"node-sass": "^4.5.3",
"protractor": "~5.1.2",
"raw-loader": "^0.5.1",
"sass-loader": "^6.0.6",
"sw-precache": "^5.2.0",
"ts-node": "~3.2.0",
"tslint": "~5.3.2",
"typescript": "~2.3.3"
}
这个问题是因为npm版本问题
为了工作 Angular 5 ;
"node": ">=6.9.5 <7.0.0",
"npm": ">=3.10.7 <4.0.0",
"yarn": ">=1.0.2 <2.0.0"
编辑:这是最新的 Angular 5 个工作依赖项:
"dependencies": {
"@angular/animations": "^5.2.0",
"@angular/common": "^5.2.0",
"@angular/compiler": "^5.2.0",
"@angular/core": "^5.2.0",
"@angular/forms": "^5.2.0",
"@angular/http": "^5.2.0",
"@angular/platform-browser": "^5.2.0",
"@angular/platform-browser-dynamic": "^5.2.0",
"@angular/router": "^5.2.0",
"core-js": "^2.4.1",
"rxjs": "^5.5.6",
"zone.js": "^0.8.19"
},
"devDependencies": {
"@angular/cli": "1.6.7",
"@angular/compiler-cli": "^5.2.0",
"@angular/language-service": "^5.2.0",
"@types/jasmine": "~2.8.3",
"@types/jasminewd2": "~2.0.2",
"@types/node": "~6.0.60",
"codelyzer": "^4.0.1",
"jasmine-core": "~2.8.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~2.0.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.2",
"ts-node": "~4.1.0",
"tslint": "~5.9.1",
"typescript": "~2.5.3"
}
只需复制粘贴 & 运行 npm install
基本上,实现这一目标的重要步骤很少。
- 将 Angular CLI 升级到最新版本。
- 修改Angular 4个应用依赖并更新依赖。
就是这样,这样您就可以轻松地将 Angular 4 应用程序升级到 Angular 5,Read more
如现在,angular5 已于 2017 年 11 月 1 日正式发布,
所以对于那些想要将旧 angular 应用程序更新为 angular 5:
的人
1) Angular 团队还提供了一个 handy tool 使从任何版本升级到 angular 5 尽可能简单。
2) 您必须将所有 angular 软件包升级到版本 5.0,运行 使用以下命令:
npm install @angular/animations@^5.0.0 @angular/common@^5.0.0 @angular/compiler@^5.0.0 @angular/compiler-cli@^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/platform-server@^5.0.0 @angular/router@^5.0.0 zone.js@^0.8.4 @angular/upgrade@^5.0.0 typescript@2.4.2 rxjs@^5.5.2
3) Angular 5 现在还依赖于 TypeScript 2.4.2 和 RxJS 5.5.2,所以你也必须升级这些包。
npm install typescript@2.4.2 --save-exact
4) 如果您依赖日期、货币、小数或百分比管道,则在 5 中您会看到格式的细微变化。对于使用 en-us 以外的语言环境的应用程序,您将需要导入它,并且可以选择从 @angular/common/i18n_data/locale_fr 和 registerLocaleData(local) 导入 locale_extended_fr。
有关管道中断更改的更多信息:
5) 在任何生命周期事件中使用工具而不是扩展:确保您不使用扩展 OnInit,或在任何生命周期事件中使用扩展。而是使用工具 .
6) 从 HttpModule 和 Http 服务切换到 HttpClientModule 和 HttpClient 服务。 HttpClient 简化了默认的人体工程学(您不再需要映射到 json 并删除不再需要的任何 map(res => res.json())
调用。)并且现在支持类型化的 return 值和拦截器。
7) 在 RxJS 5.5 中推荐的导入运算符的方式来自 rxjs/operators.
import { map, filter, mergeMap, tap } from 'rxjs/operators';
我已经尝试解释更多 here。
https://onlyforcoder.blogspot.in/2017/11/angular-5-upgrade-your-project-To-Angular5.html
更新前,将您的模板标签重命名为 ng-template。
将所有依赖项更新为最新的 Angular 和正确版本的 TypeScript。如果你使用的是Windows,你可以使用:
npm install @angular/animations@'^5.0.0' @angular/common@'^5.0.0' @angular/compiler@'^5.0.0' @angular/compiler-cli@'^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/platform-server@'^5.0.0' @angular/router@'^ 5.0.0'打字稿@2.4.2 rxjs@'^5.5.2'
npm install typescript@2.4.2 --save-exact
粘贴命令,我也遇到了同样的错误
最后,我只是将版本更改为最新版本并且成功了。
npm install @angular/animations@latest @angular/common@latest @angular/compiler@latest @angular/compiler-cli@latest @angular/core@latest @angular/forms@latest @angular/http@latest @angular/platform-browser@latest @angular/platform-browser-dynamic@latest @angular/platform-server@latest @angular/router@latest rxjs@latest --save
npm install typescript@2.4.2 --save-exact
我不确定为什么会出现此错误,因为即使我输入
npm view @angular/core versions --json
我可以看到该版本确实存在。我唯一的理论是,这可能是因为我在 Windows 而 NPM 的 Windows 版本不喜欢那些版本号...
@Vishal Gulati 的原始回答:
快速概览:
将 Angular 及其所有软件包升级到最新版本。
npm install typescript@2.4 --save-dev
npm install @angular/common@latest @angular/compiler@latest @angular/compiler-cli@latest @angular/core@latest @angular/forms@latest @angular/http@latest @angular/platform-browser@latest @angular/platform-browser-dynamic@latest @angular/platform-server@latest @angular/router@latest @angular/animations@latest --save
如果需要升级 CLI
npm uninstall -g @angular/cli
npm cache clean
npm install -g @angular/cli@latest
这是更新 Angular 5.2.0 版 CLI 的命令
npm 安装@angular/compiler-cli@5.2.0
如何更新到Angular5? 这是来自我的 package.json:
"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",
"@types/jwt-decode": "^2.2.1",
"bootstrap": "^3.3.7",
"bootstrap-sass": "^3.3.7",
"classlist.js": "^1.1.20150312",
"core-js": "^2.4.1",
"intl": "^1.2.5",
"jquery": "^3.2.1",
"jwt-decode": "^2.2.0",
"rxjs": "^5.4.2",
"zone.js": "^0.8.14"
},
"devDependencies": {
"@angular/cli": "1.4.0-rc.2",
"@angular/compiler-cli": "5.0.0",
"@angular/language-service": "5.0.0",
"@types/jasmine": "~2.5.53",
"@types/jasminewd2": "~2.0.2",
"@types/node": "~6.0.60",
"angular-ide": "^0.9.31",
"codelyzer": "~3.1.1",
"jasmine-core": "~2.6.2",
"jasmine-spec-reporter": "~4.1.0",
"karma": "~1.7.0",
"karma-chrome-launcher": "~2.1.1",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"node-sass": "^4.5.3",
"protractor": "~5.1.2",
"raw-loader": "^0.5.1",
"sass-loader": "^6.0.6",
"sw-precache": "^5.2.0",
"ts-node": "~3.2.0",
"tslint": "~5.3.2",
"typescript": "~2.3.3"
}
当我 运行 npm install 我得到这个错误
npm ERR! Windows_NT 6.1.7601 npm ERR! argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "install" npm ERR! node v6.11.2 npm ERR! npm v3.10.10 npm ERR! code ETARGET
npm ERR! notarget No compatible version found: @angular/common@5.0.0 npm ERR! notarget Valid install targets: npm ERR! notarget 5.0.0-rc.0, 5.0.0-beta.7, 5.0.0-beta.6, 5.0.0-beta.5, 5.0.0-beta.4, 5.0.0-beta.3, 5.0.0-beta.2, 5.0.0-beta.1, 5.0.0-beta.0, 4.4.4, 4.4.3, 4.4.2, 4.4.1, 4.4.0-RC.0, 4.3.6, 4.3.5, 4.3.4, 4.3.3, 4.3.2, 4.3.1, 4.3.0, 4.3.0-rc.0, 4.3.0-beta.1, 4.3.0-beta.0, 4.2.6, 4.2.5, 4.2.4, 4.2.3, 4.2.2, 4.2.1, 4.2.0, 4.2. 0-rc.2, 4.2.0-rc.1, 4.2.0-rc.0, 4.2.0-beta.1, 4.2.0-beta.0, 4.1.3, 4.1.2, 4.1.1, 4.1.0, 4.1.0-rc.0, 4.1.0-beta.1, 4.1.0-beta.0, 4.0.3, 4.0.2, 4.0.1, 4.0.0, 4.0.0- rc.6, 4.0.0-rc.5, 4.0.0-rc.4, 4.0.0-rc.3, 4.0.0-rc.2, 4.0.0-rc.1, 4.0.0-rc.0, 4.0.0-beta.8, 4.0.0-beta.7, 4.0.0-beta.6, 4.0.0-beta.5, 4.0.0-beta.4, 4.0.0-beta.3, 4.0.0-beta.2, 4.0.0-beta.1, 4.0.0-beta.0, 2.4.10, 2.4.9, 2.4.8, 2.4.7, 2.4.6, 2.4.5, 2.4.4, 2.4.3, 2.4.2, 2.4.1, 2.4.0, 2.3.1, 2.3.0, 2.3.0-rc.0, 2.3.0-beta.1, 2. 3.0-beta.0, 2.2.4, 2.2.3, 2.2.2, 2.2.1, 2.2.0, 2.2.0-rc.0, 2.2.0-beta.1, 2.2.0-beta.0, 2.1.2, 2.1.1, 2.1.0, 2.1.0-rc.0, 2.1.0-beta.0, 2.0.2, 2.0.1, 2.0.0, 2.0.0-r c.7, 2.0.0-rc.6, 2.0.0-rc.5, 2.0.0-rc.4, 2.0.0-rc.3, 2.0.0-rc.2, 2.0.0-rc.1, 2.0.0-rc.0, 0.0.0-7, 0.0.0-6, 0.0.0-5, 0.0.0-4, 0.0.0-3, 0.0.0-2, 0.0.0-1, 0.0.0-0 npm ERR! notarget npm ERR! notarget This is most likely not a problem with npm itself. npm ERR! notarget In most cases you or one of your dependencies are requesting npm ERR! notarget a package version that doesn't exist. npm ERR! notarget npm ERR! notarget It was specified as a dependency of 'gizza' npm ERR! notarget
我知道 Angular 5 仍处于测试阶段,但我想测试它。
编辑:截至 2017 年 11 月 1 日,版本 5.0.0 现已存在
编辑:版本 5.0.0 现在确实存在于 2017 年 11 月 1 日
NPM 告诉您 5.0.0 不存在。将您的 package.json 更改为建议的候选版本之一,例如 5.0.0-rc.0。很有可能它们也不完全一样,所以请阅读 npm 错误,它在这种情况下实际上很有帮助。
"dependencies": {
"@angular/animations": "5.0.0-rc.0",
"@angular/common": "5.0.0-rc.0",
"@angular/compiler": "5.0.0-rc.0",
"@angular/core": "5.0.0-rc.0",
"@angular/forms": "5.0.0-rc.0",
"@angular/http": "5.0.0-rc.0",
"@angular/platform-browser": "5.0.0-rc.0",
"@angular/platform-browser-dynamic": "5.0.0-rc.0",
"@angular/router": "5.0.0-rc.0",
"@types/jwt-decode": "^2.2.1",
"bootstrap": "^3.3.7",
"bootstrap-sass": "^3.3.7",
"classlist.js": "^1.1.20150312",
"core-js": "^2.4.1",
"intl": "^1.2.5",
"jquery": "^3.2.1",
"jwt-decode": "^2.2.0",
"rxjs": "^5.4.2",
"zone.js": "^0.8.14"
},
"devDependencies": {
"@angular/cli": "1.4.0-rc.2",
"@angular/compiler-cli": "5.0.0",
"@angular/language-service": "5.0.0",
"@types/jasmine": "~2.5.53",
"@types/jasminewd2": "~2.0.2",
"@types/node": "~6.0.60",
"angular-ide": "^0.9.31",
"codelyzer": "~3.1.1",
"jasmine-core": "~2.6.2",
"jasmine-spec-reporter": "~4.1.0",
"karma": "~1.7.0",
"karma-chrome-launcher": "~2.1.1",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"node-sass": "^4.5.3",
"protractor": "~5.1.2",
"raw-loader": "^0.5.1",
"sass-loader": "^6.0.6",
"sw-precache": "^5.2.0",
"ts-node": "~3.2.0",
"tslint": "~5.3.2",
"typescript": "~2.3.3"
}
这个问题是因为npm版本问题 为了工作 Angular 5 ;
"node": ">=6.9.5 <7.0.0",
"npm": ">=3.10.7 <4.0.0",
"yarn": ">=1.0.2 <2.0.0"
编辑:这是最新的 Angular 5 个工作依赖项:
"dependencies": {
"@angular/animations": "^5.2.0",
"@angular/common": "^5.2.0",
"@angular/compiler": "^5.2.0",
"@angular/core": "^5.2.0",
"@angular/forms": "^5.2.0",
"@angular/http": "^5.2.0",
"@angular/platform-browser": "^5.2.0",
"@angular/platform-browser-dynamic": "^5.2.0",
"@angular/router": "^5.2.0",
"core-js": "^2.4.1",
"rxjs": "^5.5.6",
"zone.js": "^0.8.19"
},
"devDependencies": {
"@angular/cli": "1.6.7",
"@angular/compiler-cli": "^5.2.0",
"@angular/language-service": "^5.2.0",
"@types/jasmine": "~2.8.3",
"@types/jasminewd2": "~2.0.2",
"@types/node": "~6.0.60",
"codelyzer": "^4.0.1",
"jasmine-core": "~2.8.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~2.0.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.2",
"ts-node": "~4.1.0",
"tslint": "~5.9.1",
"typescript": "~2.5.3"
}
只需复制粘贴 & 运行 npm install
基本上,实现这一目标的重要步骤很少。
- 将 Angular CLI 升级到最新版本。
- 修改Angular 4个应用依赖并更新依赖。
就是这样,这样您就可以轻松地将 Angular 4 应用程序升级到 Angular 5,Read more
如现在,angular5 已于 2017 年 11 月 1 日正式发布, 所以对于那些想要将旧 angular 应用程序更新为 angular 5:
的人1) Angular 团队还提供了一个 handy tool 使从任何版本升级到 angular 5 尽可能简单。
2) 您必须将所有 angular 软件包升级到版本 5.0,运行 使用以下命令:
npm install @angular/animations@^5.0.0 @angular/common@^5.0.0 @angular/compiler@^5.0.0 @angular/compiler-cli@^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/platform-server@^5.0.0 @angular/router@^5.0.0 zone.js@^0.8.4 @angular/upgrade@^5.0.0 typescript@2.4.2 rxjs@^5.5.2
3) Angular 5 现在还依赖于 TypeScript 2.4.2 和 RxJS 5.5.2,所以你也必须升级这些包。
npm install typescript@2.4.2 --save-exact
4) 如果您依赖日期、货币、小数或百分比管道,则在 5 中您会看到格式的细微变化。对于使用 en-us 以外的语言环境的应用程序,您将需要导入它,并且可以选择从 @angular/common/i18n_data/locale_fr 和 registerLocaleData(local) 导入 locale_extended_fr。
有关管道中断更改的更多信息:
5) 在任何生命周期事件中使用工具而不是扩展:确保您不使用扩展 OnInit,或在任何生命周期事件中使用扩展。而是使用工具 .
6) 从 HttpModule 和 Http 服务切换到 HttpClientModule 和 HttpClient 服务。 HttpClient 简化了默认的人体工程学(您不再需要映射到 json 并删除不再需要的任何 map(res => res.json())
调用。)并且现在支持类型化的 return 值和拦截器。
7) 在 RxJS 5.5 中推荐的导入运算符的方式来自 rxjs/operators.
import { map, filter, mergeMap, tap } from 'rxjs/operators';
我已经尝试解释更多 here。 https://onlyforcoder.blogspot.in/2017/11/angular-5-upgrade-your-project-To-Angular5.html
更新前,将您的模板标签重命名为 ng-template。
将所有依赖项更新为最新的 Angular 和正确版本的 TypeScript。如果你使用的是Windows,你可以使用:
npm install @angular/animations@'^5.0.0' @angular/common@'^5.0.0' @angular/compiler@'^5.0.0' @angular/compiler-cli@'^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/platform-server@'^5.0.0' @angular/router@'^ 5.0.0'打字稿@2.4.2 rxjs@'^5.5.2'
npm install typescript@2.4.2 --save-exact
最后,我只是将版本更改为最新版本并且成功了。
npm install @angular/animations@latest @angular/common@latest @angular/compiler@latest @angular/compiler-cli@latest @angular/core@latest @angular/forms@latest @angular/http@latest @angular/platform-browser@latest @angular/platform-browser-dynamic@latest @angular/platform-server@latest @angular/router@latest rxjs@latest --save
npm install typescript@2.4.2 --save-exact
我不确定为什么会出现此错误,因为即使我输入
npm view @angular/core versions --json
我可以看到该版本确实存在。我唯一的理论是,这可能是因为我在 Windows 而 NPM 的 Windows 版本不喜欢那些版本号...
@Vishal Gulati 的原始回答:
快速概览:
将 Angular 及其所有软件包升级到最新版本。
npm install typescript@2.4 --save-dev
npm install @angular/common@latest @angular/compiler@latest @angular/compiler-cli@latest @angular/core@latest @angular/forms@latest @angular/http@latest @angular/platform-browser@latest @angular/platform-browser-dynamic@latest @angular/platform-server@latest @angular/router@latest @angular/animations@latest --save
如果需要升级 CLI
npm uninstall -g @angular/cli
npm cache clean
npm install -g @angular/cli@latest
这是更新 Angular 5.2.0 版 CLI 的命令
npm 安装@angular/compiler-cli@5.2.0