Angular4: cannot read the property of undefined

前端 未结 1 895
栀梦
栀梦 2021-01-17 00:30

I am trying to learn angular4 with the tutorial they provided in website

Here is the code

hero.ts

export  class  Hero{

             


        
1条回答
  •  时光说笑
    2021-01-17 01:21

    Check in the template if selectedHero is set before access any of its property

    {{selectedHero.name}}

    or create an empty instance in the component (updated answer)

    selectedHero: Hero = new Hero(12, 'somename');
    

    0 讨论(0)
提交回复
热议问题