Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
5
rated 0 times [  6] [ 1]  / answers: 1 / hits: 22233  / 6 Years ago, tue, august 7, 2018, 12:00:00

I want to assign [(ngModel)] inside my .html code to an object which is empty (null or undefined), but it gives error of _co.object is null.
There are 2 cases, 1st when my object has value, 2nd when it does not. First case ngModel works fine, but when it comes to second, it gives error of being null. With elvis(?) operator i tried, it does not help.


Problem was solved !! THank you all


My .ts page


profile: Profile = {

fullName: '',
email: '',
address: '',
};

My .html page


<ion-item>
<ion-label>Full Name:</ion-label>
<ion-input [(ngModel)]="profile.fullName"></ion-input>
</ion-item>

ERROR TypeError: "_co.profile is null"


More From » angular

 Answers
6

Thank you guys. I found my mistake to be in another place. I somehow was re-asigning the 'profile' object in ngOnInit from empty to undefined. Like so:



ngOnInit(){  
//code...
if(!this.profile){
this.profile = {} as Profile; //here was the mistake which I accidentally made.
//and it was assigning my object to null
}
}

[#53792] Thursday, August 2, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
martina

Total Points: 101
Total Questions: 103
Total Answers: 111

Location: Seychelles
Member since Mon, Jun 28, 2021
3 Years ago
;