A
A
Adel Khalitov2019-01-31 14:04:04
Angular
Adel Khalitov, 2019-01-31 14:04:04

How to check if an object has options and display them?

rielt: Object = { 
  buy: {
    name: 'Купить',
    thing: {
      room: {
        name: 'Room',
        options: {
          new: {
            name: 'NewHome'
          },
          secondhend: {
            name: 'SecondHend'
          }
        }
      },
      home: {
        name: 'Home'
      }
    }
  }, 
};

<mat-form-field>
    <mat-select [(ngModel)]="selected">
      <mat-option *ngFor="let n of rielt | keyvalue" [value]="n.key">
        {{ n.value.name }}
      </mat-option>
    </mat-select>
  </mat-form-field>

  <mat-form-field *ngIf="selected">
    <mat-select>
      <mat-option *ngFor="let n of rielt[selected].thing | keyvalue" [value]="n.key">
        {{ n.value.name }}
      </mat-option>
    </mat-select>
  </mat-form-field>

Let's say an object with the key room has options, but the home object doesn't.
I need to display the field according to the same analogy, but display it only if this key has options (let's say we will display them as a checkbox).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2019-01-31
@SaveLolliPoP

if I understand you correctly...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question