I'm doing something really simple here but getting an error saying
TypeError: Cannot set property 'question' of undefined at setQuestion
and I cannot figure out what's causing it. I'm new to AngularJS so I might be way off here but does it have anything to do with the $scope?
var questions = [
{ header:"Hello World 1", body:["1 dfhgjkmhngfsdgfhytgh", "1 dfhgjkmhngfsdgfhytgh"], answer:"dfghf"},
{ header:"Hello World 2", body:["2 dfhgjkmhngfsdgfhytgh"], answer:"dfghf"},
{ header:"Hello World 3", body:["3 dfhgjkmhngfsdgfhytgh", "1 dfhgjkmhngfsdgfhytgh", "1 dfhgjkmhngfsdgfhytgh"], answer:"dfghf"},
{ header:"Hello World 4", body:["4 dfhgjkmhngfsdgfhytgh"], answer:"dfghf"},
{ header:"Hello World 5", body:["5 dfhgjkmhngfsdgfhytgh"], answer:"dfghf"}
];
this.question = {};
var setQuestion = function(index){
this.question = questions[index];
}
setQuestion(0);
console.log("Question is: " + this.question.header);
Appreciate any help or explanation