Angular 6 - ERROR TypeError: Cannot read property 'value' of undefined

前端 未结 3 1455
你的背包
你的背包 2020-12-16 05:11

I\'m new to Angular and Typescript and cannot get to the bottom of this console error: \"ERROR TypeError: Cannot read property \'value\' of undefined\"

I\'m calling

相关标签:
3条回答
  • Angular 7 - ERROR TypeError: Cannot read property 'value' of undefined

    You can check for the object value by using the ? operator.

    Example:

    <div> {{ joke?.value }} </div>
    
    0 讨论(0)
  • 2020-12-16 05:19

    You can use *ngIf until getting resopnse

    below is the sample,

    <div *ngIf="joke">{{ joke.value }}</div>
    
    0 讨论(0)
  • 2020-12-16 05:31

    Just use

    <div>{{ joke?.value }}</div>
    

    Your joke object doesn't have the value until the API response arrives. Thus use ? to apply the null check until the response arrives.

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