从Angular 8升级到Angular 9-错误

3

我按照官方文档更新了Angular应用程序,更新完成后,当我运行ng serve时,出现以下错误:

ERROR in app/src/app/users/add/add.component.html:14:48 - error NG2345: Argument of type 'AbstractControl' is not assignable to parameter of type 'FormControl'.
  Type 'AbstractControl' is missing the following properties from type 'FormControl': registerOnChange, registerOnDisabledChange, _applyFormState

  <ng-container *ngFor="let error of errors(addNewUserForm.get('username'))">



   Error occurs in the template of component UserProfileComponent.
app/src/app/registration/dialog/dialog.component.html:1:1 - error NG8001: 'mat-horizontal-stepper' is not a known element:
1. If 'mat-horizontal-stepper' is an Angular component, then verify that it is part of this module.
2. If 'mat-horizontal-stepper' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.

  <mat-horizontal-stepper linear #stepperRegistration>

mat-dialog-actionsmat-stepmat-dialog-content等都出现了相同的错误。

而且...

Error occurs in the template of component DialogComponent.
app/src/app/registration/dialog/dialog.component.html:46:13 - error NG8002: Can't bind to 'errorStateMatcher' since it isn't a known property of 'input'.

[errorStateMatcher]="matcher"

这是我的 package.json 文件。

"dependencies": {
    "@angular/animations": "^9.0.0-rc.10",
    "@angular/cdk": "^8.2.3",
    "@angular/common": "^9.0.0-rc.10",
    "@angular/compiler": "^9.0.0-rc.10",
    "@angular/core": "^9.0.0-rc.10",
    "@angular/flex-layout": "^8.0.0-beta.27",
    "@angular/forms": "^9.0.0-rc.10",
    "@angular/material": "^8.2.3",
    "@angular/platform-browser": "^9.0.0-rc.10",
    "@angular/platform-browser-dynamic": "^9.0.0-rc.10",
    "@angular/router": "^9.0.0-rc.10",
    "@angular/service-worker": "^9.0.0-rc.10",
    "@ngrx/effects": "^8.6.0",
    "@ngrx/schematics": "^8.6.0",
    "@ngrx/store": "^8.6.0",
    "@ngrx/store-devtools": "^8.6.0",
    "font-awesome": "^4.7.0",
    "hammerjs": "^2.0.8",
    "jquery": "^3.4.1",
    "keycloak-angular": "^7.1.0",
    "keycloak-js": "^6.0.1",
    "popper.js": "^1.16.0",
    "rxjs": "~6.5.4",
    "tslib": "^1.10.0",
    "zone.js": "~0.10.2"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.900.0-rc.10",
    "@angular-devkit/schematics": "^8.3.23",
    "@angular/cli": "^9.0.0-rc.10",
    "@angular/compiler-cli": "^9.0.0-rc.10",
    "@angular/language-service": "^9.0.0-rc.10",
    "@compodoc/compodoc": "^1.1.11",
    "@types/jasmine": "~3.3.8",
    "@types/jasminewd2": "^2.0.8",
    "@types/node": "^12.11.1",
    "codelyzer": "^5.1.2",
    "jasmine-core": "~3.4.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.1.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.5.1",
    "protractor": "~5.4.0",
    "rxjs-tslint-rules": "^4.28.0",
    "ts-node": "~7.0.0",
    "tslint": "^5.20.1",
    "tslint-angular": "^3.0.2",
    "tslint-sonarts": "^1.9.0",
    "typescript": "~3.7.5",
    "webpack-bundle-analyzer": "^3.6.0"
  }
2个回答

1

我可以通过更新延迟加载模块的路由来解决类似的错误

loadChildren: './some/route/some-route.module#SomeRouteModule',

loadChildren: () => import('./some/route.module').then(m => m.SomeRouteModule),

0

检查你的模块是否有组件对话框。你需要导入MatStepperModule。同样地,更新使用了其他来自Material库的模块:

import {MatStepperModule} from '@angular/material/stepper';
import {MatDialogModule} from '@angular/material/dialog';

所以,[errorStateMatcher]="matcher"中的错误应该通过上面的解决方案来修复,因为它找不到组件组件和它的@Input()


我已经在我的共享模块中导入了所有这些东西…… 在更新之前,所有这些都是可以工作的。 - Arter
你是否按照Angular团队提供的更新指南进行操作?他们明确指出需要运行ng update @angular/material --next,如果需要,则必须使用--force。请查看此链接从Angular 8.0升级到9.0 - Ratnadeep Bhattacharyya
我查看了你的 package.json 文件,发现关于 material library,next 标签是 9.0.0-rc.8,而在你的 package.json 文件中是 8.2.3,这是 latest 标签。 - Ratnadeep Bhattacharyya
是的,现在我尝试运行 npm i @angular/material@9.0.0-rc.8,但我仍然遇到了同样的问题。 - Arter
你解决了这个问题吗?我在将 Angular 从 8 升级到 9 的过程中遇到了相同的问题。 - Daniele

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接