Angular 5 - Stop errors from undefined object before loading data

后端 未结 4 1050
旧时难觅i
旧时难觅i 2021-02-15 13:57

What\'s the best way to prevent errors in console from objects that are still undefined?

Let\'s say I have this

name : string;
constructor(private data:          


        
4条回答
  •  太阳男子
    2021-02-15 14:14

    Just initialize your variable

    name : string = "";
    

    or you can do it inside of the constructor

    this.name = "";
    

提交回复
热议问题