Ionic framework ngif无法读取属性';肩膀';空的

Ionic framework ngif无法读取属性';肩膀';空的,ionic-framework,ionic3,Ionic Framework,Ionic3,我有下表,但我应该检查变量是否为null,因此我不会打印该表,但我尝试了下表,我得到了错误,无法读取null的属性'shoels' <div ng-if="shoulders!=null"> <ion-label color="danger" ><b>Shoulders</b></ion-label> <ion-grid> <ion-row text-wrap> <ion-col w

我有下表,但我应该检查变量是否为null,因此我不会打印该表,但我尝试了下表,我得到了错误,无法读取null的属性'shoels'

<div ng-if="shoulders!=null">
<ion-label color="danger" ><b>Shoulders</b></ion-label>
<ion-grid>
    <ion-row text-wrap>
        <ion-col width-25 >Exercises</ion-col>
        <ion-col width-25 >Machine ID</ion-col>
        <ion-col width-25 >Days</ion-col>
        <ion-col  width-25>Hints</ion-col>
      </ion-row> 
    <ion-row text-wrap *ngFor="let exercise of shoulders.shoulders |keys">
        <ng-container  *ngFor="let machine of MachinesDetails "> 
            <ng-container  *ngIf="machine.machine_no == exercise.key">
      <ion-col > {{machine.name}}</ion-col>
      <ion-col > {{machine.machine_no}}</ion-col>
    </ng-container >
    </ng-container >
      <ion-col > {{exercise.value}}</ion-col>
      <ng-container  *ngFor="let hints of shoulders.hints[exercise.key] |keys ">        
          <ion-col > {{hints.value}} </ion-col>
    </ng-container >
    </ion-row>
  </ion-grid></div>

如果您不确定是否满足条件,则应使用可选条件(“?”)提供任何帮助

组件:

export class ViewworkoutPage {
  shoulders:any = {
     shoulders: '',
     hints: ''
  };
<div ng-if="shoulders && shoulders?.shoulders">
<ion-label color="danger" ><b>Shoulders</b></ion-label>
<ion-grid>
    <ion-row text-wrap>
        <ion-col width-25 >Exercises</ion-col>
        <ion-col width-25 >Machine ID</ion-col>
        <ion-col width-25 >Days</ion-col>
        <ion-col  width-25>Hints</ion-col>
      </ion-row> 
    <ion-row text-wrap *ngFor="let exercise of shoulders.shoulders |keys">
        <ng-container  *ngFor="let machine of MachinesDetails "> 
            <ng-container  *ngIf="machine.machine_no == exercise.key">
      <ion-col > {{machine.name}}</ion-col>
      <ion-col > {{machine.machine_no}}</ion-col>
    </ng-container >
    </ng-container >
      <ion-col > {{exercise.value}}</ion-col>
      <ng-container  *ngFor="let hints of shoulders.hints[exercise.key] |keys ">        
          <ion-col > {{hints.value}} </ion-col>
    </ng-container >
    </ion-row>
  </ion-grid></div>
模板:

export class ViewworkoutPage {
  shoulders:any = {
     shoulders: '',
     hints: ''
  };
<div ng-if="shoulders && shoulders?.shoulders">
<ion-label color="danger" ><b>Shoulders</b></ion-label>
<ion-grid>
    <ion-row text-wrap>
        <ion-col width-25 >Exercises</ion-col>
        <ion-col width-25 >Machine ID</ion-col>
        <ion-col width-25 >Days</ion-col>
        <ion-col  width-25>Hints</ion-col>
      </ion-row> 
    <ion-row text-wrap *ngFor="let exercise of shoulders.shoulders |keys">
        <ng-container  *ngFor="let machine of MachinesDetails "> 
            <ng-container  *ngIf="machine.machine_no == exercise.key">
      <ion-col > {{machine.name}}</ion-col>
      <ion-col > {{machine.machine_no}}</ion-col>
    </ng-container >
    </ng-container >
      <ion-col > {{exercise.value}}</ion-col>
      <ng-container  *ngFor="let hints of shoulders.hints[exercise.key] |keys ">        
          <ion-col > {{hints.value}} </ion-col>
    </ng-container >
    </ion-row>
  </ion-grid></div>

肩膀
练习
机器ID
天
提示
{{machine.name}
{{machine.machine{u no}
{{exercise.value}}
{{hits.value}

最后,我用下面的解决方案解决了这个问题,如果我错过了*

<div *ngIf="shoulders">
    <ion-label color="danger" ><b>Shoulders</b></ion-label>
    <ion-grid>
        <ion-row text-wrap>
            <ion-col width-25 >Exercises</ion-col>
            <ion-col width-25 >Machine ID</ion-col>
            <ion-col width-25 >Days</ion-col>
            <ion-col  width-25>Hints</ion-col>
          </ion-row> 
        <ion-row text-wrap *ngFor="let exercise of shoulders.shoulders |keys">
            <ng-container  *ngFor="let machine of MachinesDetails "> 
                <ng-container  *ngIf="machine.machine_no == exercise.key">
          <ion-col > {{machine.name}}</ion-col>
          <ion-col > {{machine.machine_no}}</ion-col>
        </ng-container >
        </ng-container >
          <ion-col > {{exercise.value}}</ion-col>
          <ng-container  *ngFor="let hints of shoulders.hints[exercise.key] |keys ">        
              <ion-col > {{hints.value}} </ion-col>
        </ng-container >
        </ion-row>
      </ion-grid>
</div>

肩膀
练习
机器ID
天
提示
{{machine.name}
{{machine.machine{u no}
{{exercise.value}}
{{hits.value}

你需要用空值的对象属性检查肩部。这意味着什么?你能给我一个例子吗?我尝试了这个和这个,但我得到了相同的错误