私は角度のを使用しようとすると問題を抱えている*ngForし、*ngIf同じ要素に。
のコレクションをループしようとする*ngForと、コレクションはと見nullなされ、その結果、テンプレートのプロパティにアクセスしようとすると失敗します。
@Component({
  selector: 'shell',
  template: `
    <h3>Shell</h3><button (click)="toggle()">Toggle!</button>
    <div *ngIf="show" *ngFor="let thing of stuff">
      {{log(thing)}}
      <span>{{thing.name}}</span>
    </div>
  `
})
export class ShellComponent implements OnInit {
  public stuff:any[] = [];
  public show:boolean = false;
  constructor() {}
  ngOnInit() {
    this.stuff = [
      { name: 'abc', id: 1 },
      { name: 'huo', id: 2 },
      { name: 'bar', id: 3 },
      { name: 'foo', id: 4 },
      { name: 'thing', id: 5 },
      { name: 'other', id: 6 },
    ]
  }
  toggle() {
    this.show = !this.show;
  }
  log(thing) {
    console.log(thing);
  }
}私は簡単な解決策が移動することです知っている*ngIfレベルをアップしますが、リストの項目をループのようなシナリオのためにul、私は空のいずれかで終わるだろうliコレクションが空である、または私の場合はlisが冗長コンテナ要素に包まれました。
このplnkrでの例。
コンソールエラーに注意してください。
EXCEPTION: TypeError: Cannot read property 'name' of null in [{{thing.name}} in ShellComponent@5:12]
私は何か間違ったことをしていますか、これはバグですか?