How do I combine a template reference variable with ngIf?

后端 未结 5 826
抹茶落季
抹茶落季 2020-12-14 06:16
tRefVar is {{tRefVar.foo}}

Even though the

5条回答
  •  春和景丽
    2020-12-14 06:50

    As given in the above answer by @lexith, Because you're using *ngIf the corresponding template variable is not defined at the time. We can avoid this confusion by modifying the code

    with
    and that will work.


    Final code:

    @Component({
      selector: 'my-app',
      template: `
        

    Hello {{name}}, tRefVar is {{tRefVar.foo}}

    tRefVar is {{tRefVar?.foo}}
    `, })

    Modified Plunker

提交回复
热议问题