Mat select and mat option

时间:2019-12-11 11:28:34

标签: angular

我正在尝试运行此代码

<mat-header-cell *matHeaderCellDef mat-sort-header class="header-primary-text"> Response </mat- header-cell>
<mat-cell *matCellDef="let element">
  <!-- Code for new questions and dropdown - Ramki -->
  <!-- mat-form-field style="width: 48%" -->
  <div *ngIf="element.name == 'Select the complexity of Application'">
    <mat-select [(ngModel)]="element.QuestionCode" placeholder="Select the complexity"
      <mat-option *ngFor="let qc of element.QuestionCode" value="{{qc}}">
        {{qc}} </mat-option>
    </mat-select>
  </div>

我收到如下错误:

  

意外的结束标记“ mat-option”。标签可能会发生   已被另一个标签关闭。有关更多信息,请参见   https://www.w3.org/TR/html5/syntax.html#closing-elements-that-have-implied-end-tags

("-option *ngFor="let qc of element.QuestionCode" value="{{qc}}">
{{qc}} [ERROR ->]</mat-option>
</mat-select>
</div>

我要去哪里错了?

我是Angular的新手。感谢您的帮助

1 个答案:

答案 0 :(得分:0)

我遇到了类似的问题,并且我以这种方式解决了。这可能会帮助许多像我一样面临同样问题的人。

<div *ngIf="element.name == 'Select the complexity of Application'">
    <mat-select [(ngModel)]='"element.QuestionCode"' placeholder="Select the complexity"
      <mat-option *ngFor="let qc of element.QuestionCode" [value]='qc'>
        {{qc}} </mat-option>
    </mat-select>
  </div>