Reputation: 493
I initialized an array with 3 values and later I try to add one more item to the array. It fails and I got an exception says "Uncaught ReferenceError: viewModel is not defined ". Any idea why is this?
var ViewModel = {
// These are the initial options
availableCountries: ko.observableArray(['France', 'Germany', 'Spain'])
};
viewModel.availableCountries.push('China');
ko.applyBindings(ViewModel);
Upvotes: 0
Views: 62
Reputation: 55339
JavaScript is case sensitive, so you need to capitalize your variables consistently everywhere they're used. To fix the error, you can make the "v" uppercase in the second statement:
ViewModel.availableCountries.push('China');
Or you can make the "V" lowercase in the first and third statements.
Upvotes: 1