cnak2
cnak2

Reputation: 1841

Property is coming across as 'undefined' in html

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

Answers (1)

Sajeetharan
Sajeetharan

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

Related Questions