【问题标题】:Unable To Add Angular Material To Angular Custom Library无法将 Angular 材质添加到 Angular 自定义库
【发布时间】:2019-05-09 21:07:55
【问题描述】:

我想构建一个基于角材料库的自定义库,因此我将角材料添加到我的角项目中,并在我的组件中测试了材料组件,它运行良好。但是在我尝试在创建 VIA ng 生成库的库中使用角度材料之后,我被错误淹没了。

错误:

BUILD ERROR
: Can't bind to 'ngForOf' since it isn't a known property of 'mat-tab'.
1. If 'mat-tab' is an Angular component and it has 'ngForOf' input, then verify that it is part of this module.
2. If 'mat-tab' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("<div class="pwc-tabs">
  <mat-tab-group disableRipple>
    <mat-tab  [ERROR ->]*ngFor="let tab of tabContent" label="{{tab.title}}"> {{tab.content}} </mat-tab>
  </mat-tab-group>

")

我尝试在库导入和导出中添加材料模块,但没有任何效果

tabs.module.ts

import { NgModule } from '@angular/core';
import { TabsComponent } from './tabs.component';
import { MatTabsModule } from '@angular/material/tabs';
import { MatExpansionModule } from '@angular/material/expansion';

@NgModule({
  declarations: [TabsComponent],
  imports: [
    MatTabsModule,
    MatExpansionModule
  ],
  exports: [
    MatTabsModule,
    MatExpansionModule,
    TabsComponent
  ]
})
export class TabsModule { }

tabs.html

<div class="tabs">
  <mat-tab-group disableRipple>
    <mat-tab  *ngFor="let tab of tabContent" label="{{tab.title}}"> {{tab.content}} </mat-tab>
  </mat-tab-group>

  <mat-expansion-panel #tabsExpansionPanel>
    <mat-expansion-panel-header>
      <mat-panel-description>
        <i *ngIf="!tabsExpansionPanel.expanded" class="material-icons expansion-panel-icons">
          keyboard_arrow_down
        </i>
        <i *ngIf="tabsExpansionPanel.expanded" class="material-icons expansion-panel-icons">
          keyboard_arrow_up
        </i>
      </mat-panel-description>
    </mat-expansion-panel-header> 
  </mat-expansion-panel>
</div>

【问题讨论】:

标签: angular angular-material angular-cli


【解决方案1】:

尝试将 CommonModule 添加到 tabs.module.ts 的导入中

【讨论】:

    猜你喜欢
    • 2019-04-20
    • 2019-02-25
    • 2019-06-11
    • 1970-01-01
    • 1970-01-01
    • 2018-01-02
    • 2018-02-07
    • 2019-07-06
    • 1970-01-01
    相关资源
    最近更新 更多