【问题标题】:Angular + Material can't use derectives in dialogsAngular + Material 不能在对话框中使用指令
【发布时间】:2022-11-11 10:07:57
【问题描述】:

这是对话内容

<div mat-dialog-content>
    <form>
        <h1>New Shipment</h1>
        <div class="form-outline mb-4">
            <select #shipmentStatusd name="cars" class="form-control">
                <div *ngFor="let status of shipmentStatuses">{{status}}</div>
            </select>
            <label class="form-label">shipmentStatus</label>
        </div>

    </form>

</div>

在对话框的 component.ts 中,我有这个变量

 shipmentStatuses = ["INITIATED", "SENT", "ARRIVED", "DELIVERED"];

这是我的应用程序模块(我只有一个)

@NgModule({
  declarations: [
    AppComponent,
    UsersComponent,
    LoginComponent,
    CompaniesComponent,
    OfficesComponent,
    ShipmentsComponent
  ],
  imports: [
    AppRoutingModule,
    CommonModule,
    FormsModule,
    ReactiveFormsModule,
    BrowserModule,
    FontAwesomeModule,
    RouterModule,
    HttpClientModule,
    BrowserAnimationsModule,
    MatCardModule,
    MatIconModule,
    MatChipsModule,
    MatInputModule,
    MatDialogModule,
  ],
  providers: [
    AuthGuardService,
    AuthService
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

我收到这个错误

NG0303: Can't bind to 'ngForOf' since it isn't a known property of 'div'.

我真的不知道发生了什么,我也不能在对话框中使用 ngModel

【问题讨论】:

    标签: angular typescript angular-material


    【解决方案1】:

    原来我必须在模块声明和模块 entryComponents 中添加对话框组件。我不知道为什么在任何地方都没有提到它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-15
      • 2017-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多