显示<mat-form-field>取决于<mat-select>

时间:2018-02-11 09:53:23

标签: angular typescript angular-material

我希望根据另一个来展示(另一个)。我试图设置* ngIf以检查第一个字段中是否有&#39; &#39;,但它不起作用。什么是实现它的正确方法?

    <mat-form-field>
    <mat-select placeholder="Manufacterer" [(ngModel)]="manufactererValue" name="manufacterer">
      <mat-option> </mat-option>
      <mat-option *ngFor="let server of servers" [value]="server.manufacterer">
        {{server.manufacterer}}
      </mat-option>
    </mat-select>
    </mat-form-field>
    </tr>
    <tr>
    <mat-form-field *ngIf="manufactererValue != ' '">
    <mat-select placeholder="Model" [(ngModel)]="modelValue" name="model">
      <mat-option *ngFor="let server of servers" [value]="server.manufacterer">
        {{server.model}}
      </mat-option>
    </mat-select>
    </mat-form-field>

1 个答案:

答案 0 :(得分:1)

您不必明确使用限定符,如manufactererValue ==''或manufactererValue!=''。与在JavaScript中一样,空字符串将被评估为false。

尝试

<mat-form-field *ngIf="!manufactererValue">