Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assign null to interface in angular 4

i have a interface in angular4

interface StatusDetail {
    statusName: string,
    name: string
}

and i have assigned some values to it like

//angular Component

     export class EditComponent implements OnInit{
         statusDetail: StatusDetail;
         ngOnInit() {
           this.statusDetail.statusName = 'text Status';
           this.statusDetail.name= 'text Name';
         }
     }  

i'm trying to reset to default null like this

         SetNull() { 
           this.statusDetail = null
         }

but it gives error

Type null is not assignable to type StatusDetail

how can i do this?

like image 277
Faisal Avatar asked Jan 28 '23 05:01

Faisal


1 Answers

You need to declare statusDetail as StatusDetail | null:

export class EditComponent implements OnInit{
     statusDetail: StatusDetail | null;
     ngOnInit() {
       this.statusDetail.statusName = 'text Status';
       this.statusDetail.name= 'text Name';
     }
 }  
like image 131
Daniel Hilgarth Avatar answered Jan 31 '23 21:01

Daniel Hilgarth