Michael
Michael

Reputation: 13614

Some misunderstand in AngularJS

In my controller I have this definition:

var self = this;
this.game= gameArchive;

I have this row in my view:

<input type="checkbox"
    checklist-model="builderStep2.game.ModelItems"
    checklist-value="model.Id"> {{model.Name}}

where builderStep2 is controller name.

And also I have this row code:

self.game.ModelItems.push(someID);

When user press on the check button the array is created and the value is added to game.ModelItems, but when I try to fill the array programmatically by this row:

self.game.ModelItems.push(someID);

it seems that array is not creates and I get this error:

TypeError: Cannot read property 'push' of null

Any idea why does it happen?

Upvotes: 0

Views: 32

Answers (1)

Wes Copeland
Wes Copeland

Reputation: 361

push() belongs to Array.prototype. If game.ModelItems is not an array, push() will not work.

I'm not sure what gameArchive is doing, but you could try in your controller this.game.ModelItems = []; and I have a feeling push() would work.

Upvotes: 3

Related Questions