Reputation: 1841
I have an object that I declare in my controller like this:
private addressData: { address_type:'personal', state: 'State'};
In my html, I have a select control I'm trying to populate with the default 'address_type'.
<select id="address_type" name="address_type" [(ngModel)]="addressData.address_type">
<option value="select" ng-disabled="true"> -- Select -- </option>
<option value="personal">personal</option>
<option value="business">business</option>
<option value="other">other</option>
</select>
For some reason I'm getting an error saying the 'cannot read property of 'address_type' undefined'
What am I missing?
Upvotes: 0
Views: 35
Reputation: 222572
You need to assign the object
Change
From
private addressData : { address_type:'personal', state: 'State'};
To
addressData = { address_type:'personal', state: 'State'};
EDIT
As vikas
mentioned below , Data-bound properties must be typescript public property Angular never binds to a TypeScript private property.
Upvotes: 2