【问题标题】:Angular Material Problem in version 8.2.14版本 8.2.14 中的角材料问题
【发布时间】:2020-12-09 16:18:48
【问题描述】:

编辑(08/20/2020 14:12h)

由于 HTML 解析,我得到了更多详细信息:

Uncaught Error: Template parse errors:
'mat-card-title' is not a known element:
1. If 'mat-card-title' is an Angular component, then verify that it is part of this module.
2. If 'mat-card-title' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("
<mat-card>
  <mat-card-header>
    [ERROR ->]<mat-card-title>Login</mat-card-title>
  </mat-card-header>
  <mat-card-content>
"): ng:///AppModule/LoginComponent.html@11:4
'mat-card-header' is not a known element:
1. If 'mat-card-header' is an Angular component, then verify that it is part of this module.
2. If 'mat-card-header' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("

更新

我解决了大部分问题。现在这个案例是关于 @angular/cdk 包的:

node_modules/@angular/cdk/tree/padding.d.ts:36:9 - error TS1086: An accessor cannot be declared in an ambient context.

36     set indent(indent: number | string);
           ~~~~~~
node_modules/@angular/cdk/tree/toggle.d.ts:17:9 - error TS1086: An accessor cannot be declared in an ambient context.

17     get recursive(): boolean;
           ~~~~~~~~~
node_modules/@angular/cdk/tree/toggle.d.ts:18:9 - error TS1086: An accessor cannot be declared in an ambient context.

18     set recursive(value: boolean);
           ~~~~~~~~~
node_modules/@angular/cdk/tree/tree.d.ts:37:9 - error TS1086: An accessor cannot be declared in an ambient context.

37     get dataSource(): DataSource<T> | Observable<T[]> | T[];
           ~~~~~~~~~~
node_modules/@angular/cdk/tree/tree.d.ts:38:9 - error TS1086: An accessor cannot be declared in an ambient context.

38     set dataSource(dataSource: DataSource<T> | Observable<T[]> | T[]);
           ~~~~~~~~~~
node_modules/@angular/cdk/tree/tree.d.ts:103:9 - error TS1086: An accessor cannot be declared in an ambient context.

103     get data(): T;
            ~~~~
node_modules/@angular/cdk/tree/tree.d.ts:104:9 - error TS1086: An accessor cannot be declared in an ambient context.

104     set data(value: T);
            ~~~~
node_modules/@angular/cdk/tree/tree.d.ts:106:9 - error TS1086: An accessor cannot be declared in an ambient context.

106     get isExpanded(): boolean;
            ~~~~~~~~~~
node_modules/@angular/cdk/tree/tree.d.ts:107:9 - error TS1086: An accessor cannot be declared in an ambient context.

107     get level(): number;

CMD 控制台

npm WARN karma-jasmine-html-reporter@1.5.4 requires a peer of jasmine-core@>=3.5 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/cdk@10.1.3 requires a peer of @angular/core@^10.0.0 || ^11.0.0-0 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/cdk@10.1.3 requires a peer of @angular/common@^10.0.0 || ^11.0.0-0 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/material@8.2.3 requires a peer of @angular/cdk@8.2.3 but none is installed. You must install peer dependencies yourself.

有什么解决办法吗?谢谢! :)


看到关于这个主题的这些问题:@angular/material/index.d.ts' is not a moduleHow to import Angular Material in project?,并按如下方式实现模块,编译器给了我一个错误。

angular-material.module.ts

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

import {
  MatCardModule,
  MatDialogModule,
  MatMenuModule,
   MatButtonModule,
   MatToolbarModule,
   MatIconModule,
   MatBadgeModule,
   MatSidenavModule,
   MatListModule,
   MatGridListModule,
   MatFormFieldModule,
   MatInputModule,
   MatSelectModule,
   MatRadioModule,
   MatDatepickerModule,
   MatNativeDateModule,
   MatChipsModule,
   MatTooltipModule,
   MatTableModule,
   MatPaginatorModule,
   MatProgressSpinnerModule
} from '@angular/material';

@NgModule({
   imports: [
    MatCardModule, 
    MatDialogModule, 
    MatMenuModule,
    MatProgressSpinnerModule,
      CommonModule,
      MatButtonModule,
      MatToolbarModule,
      MatIconModule,
      MatSidenavModule,
      MatBadgeModule,
      MatListModule,
      MatGridListModule,
      MatFormFieldModule,
      MatInputModule,
      MatSelectModule,
      MatRadioModule,
      MatDatepickerModule,
      MatNativeDateModule,
      MatChipsModule,
      MatTooltipModule,
      MatTableModule,
      MatPaginatorModule
   ],
   exports: [
    MatCardModule, 
    MatDialogModule, 
    MatMenuModule,
    MatProgressSpinnerModule,
      MatButtonModule,
      MatToolbarModule,
      MatIconModule,
      MatSidenavModule,
      MatBadgeModule,
      MatListModule,
      MatGridListModule,
      MatInputModule,
      MatFormFieldModule,
      MatSelectModule,
      MatRadioModule,
      MatDatepickerModule,
      MatChipsModule,
      MatTooltipModule,
      MatTableModule,
      MatPaginatorModule
   ],
   providers: [
      MatDatepickerModule,
   ]
})

export class AngularMaterialModule { }

最近,我在 package.json 中添加了这样的内容,以放置与 node_modules/@angular/material/index.d.ts 兼容的旧版本:

"dependencies": {
    "@angular/animations": "~8.2.14",
    "@angular/common": "~8.2.14",
    "@angular/compiler": "~8.2.14",
    "@angular/core": "~8.2.14",
    "@angular/forms": "~8.2.14",
    "@angular/material": "^8.2.3",
    "@angular/platform-browser": "~8.2.14",
    "@angular/platform-browser-dynamic": "~8.2.14",
    "@angular/router": "~8.2.14",
    "chokidar": "^3.4.2",
    "core-js": "^3.6.5",
    "rxjs": "~6.4.0",
    "tslib": "^1.10.0",
    "zone.js": "~0.9.1"
  },

最后,在 app.module.ts 我添加了依赖文件:

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { LoginComponent } from './login/login.component';
import { LogoutComponent } from './logout/logout.component';
import { AngularMaterialModule } from './angular-material.module';
import {HTTP_INTERCEPTORS, HttpClientModule} from '@angular/common/http';
import { HeaderComponent } from './header/header.component';
import { UserComponent } from './user/user.component';
import { FooterComponent } from './footer/footer.component';
import {BasicAuthHtppInterceptorService} from './service/basic-auth-interceptor.service';

我的应用结构是这样的:

我应该怎么做才能在这个版本上显示 HTML 标签?

【问题讨论】:

    标签: node.js angular typescript


    【解决方案1】:

    根据您的 package.json,您使用的是 Angular 8.3,并且您拥有 @angular/cdk@10.1.3。您可以使用

    降级 angular/cdk 版本
    npm i @angular/cdk@8.2.1 
    

    或者你可以通过运行将你的 Angular 版本升级到 v9:

    ng update @angular/core @angular/cli
    

    这会将您的本地 Angular 版本更新为 9。然后,为了同步素材,运行:ng update @angular/material

    【讨论】:

    • 我明白了,感谢您的好奇,但我仍需要使用 8.2.14 版本,并且所有材料都通过 HTML 运行。例如,stackoverflow.com/questions/43479557/…
    • 是的,您的所有版本都保持在 8.2 或以下。它会起作用的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-13
    • 1970-01-01
    • 1970-01-01
    • 2016-07-29
    • 2019-04-24
    • 2020-12-17
    • 2019-06-15
    相关资源
    最近更新 更多