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?
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';
     }
 }  
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With