[英]How to update angular material
將項目中的角度材質更新到最新版本material@2.0.0-alpha.8-3
的最佳方法是什么?
我試過了:
npm install --save @angular/material @angular/cdk
您將需要使用 npm update 命令。 一個例子看起來像這樣。
npm update @angular/material @angular/cdk
這將安裝最新的穩定版本。 如果您想針對特定版本,則必須通過在@ 符號后添加版本來指定它。
此外,您可以使用以下命令檢查過時的軟件包
npm outdated
這是有關 npm 更新的文檔。
使用以下命令:
ng update @angular/material
注意:我最近使用這個命令從版本 8 升級到版本 9。我沒有測試過舊版本。 適用於版本 9 之后的所有版本。
以下步驟幫助我將材質主題從 v9 更新到 v10。
先把舊包去掉
npm remove @angular/material @angular/cdk
然后安裝最新的包
npm add @angular/material @angular/cdk
Way 1
您是否嘗試過使用簡單的npm i @angular/material
? 正如 npmjs 報道的那樣,他將獲取最新版本。
Way 2
刪除文件package-lock.json
並在您的package.json
檢查您是否使用最新的角度材料,然后只需執行npm i
first remove from `package-lock.json` this
// "@angular/material": {
// "version": "6.4.7",
// "resolved": "https://registry.npmjs.org/@angular/material/-/material-6.4.7.tgz",
// "integrity": "sha512-SdNx7Xovi24Kw9eU6lkLhY/7f2M7L9F+/uh6XuPr4jbGgCUVVpeeVI5ztZhsZRbj1sN+/r1p5w8u62apWWl5Ww==",
// "requires": {
// "parse5": "^5.0.0",
// "tslib": "^1.7.1"
// },
// "dependencies": {
// "parse5": {
// "version": "5.1.0",
// "resolved": "https://registry.npmjs.org/parse5/-/parse5-5.1.0.tgz",
// "integrity": "sha512-
fxNG2sQjHvlVAYmzBZS9YlDp6PTSSDwa98vkD4QgVDDCAo84z5X1t5XyJQ62ImdLXx5NdIIfihey6xpum9/gRQ==",
// "optional": true
// }
// }
// },
// "@angular/cdk": {
// "version": "7.3.7",
// "resolved": "https://registry.npmjs.org/@angular/cdk/-/cdk-7.3.7.tgz",
// "integrity": "sha512-xbXxhHHKGkVuW6K7pzPmvpJXIwpl0ykBnvA2g+/7Sgy5Pd35wCC+UtHD9RYczDM/mkygNxMQtagyCErwFnDtQA==",
// "requires": {
// "parse5": "^5.0.0",
// "tslib": "^1.7.1"
// },
// "dependencies": {
// "parse5": {
// "version": "5.1.0",
// "resolved": "https://registry.npmjs.org/parse5/-/parse5-5.1.0.tgz",
// "integrity": "sha512-fxNG2sQjHvlVAYmzBZS9YlDp6PTSSDwa98vkD4QgVDDCAo84z5X1t5XyJQ62ImdLXx5NdIIfihey6xpum9/gRQ==",
// "optional": true
// }
// }
// },
second remove from `package.json` this line
// "@angular/material": "^6.4.7",
// "@angular/cdk": "^7.3.7",
then finaly run this
npm install --save @angular/material @angular/cdk
最好使用 angular 工具通過執行以下操作來升級ng update
:
ng update @angular/material @angular/cli
在極少數情況下,當您觸摸某些材料混合時,此 angular api 不起作用,在這種情況下,我建議使用npm
(或習慣使用的紗線)作為:
# Removing the material previous version files from node_modules in the explorer or with the command
npm remove @angular/material @angular/cdk
# Or by using yarn:
yarn remove @angular/material @angular/cdk
# And re-install the new version of the packages:
npm i @angular/material@latest @angular/cdk@latest
# with yarn it gives:
yarn add @angular/material@latest @angular/cdk@latest
你應該總是嘗試使用ng update @angular/material
因為它不僅更新包。 它還遷移您的代碼,例如導入等。
我從 7 遷移到 11,導入從import { MatSnackBar } from '@angular/material';
import { MatSnackBar } from '@angular/material/snack-bar';
這是我用於更新角度材料的命令
npm install --save @ angular / material @ 8.x @ angular / cdk @ 8.x @ angular / animations @ 8.x
從現有的較低版本更新角度材料
npm 刪除 @angular/material @angular/cdk
npm 添加@angular/material @angular/cdk
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.