I have the following HTML:
<div class="row" ng-repeat="question in currentTemplate.questions">
<div class="col-xs-4" ng-show="editingQuestion[$index]">
<select style="width:100%;" ng-model="editingCurrentlySelectedAnswerOption[$index]"
ng-options="answerOption as answerOption.back for answerOption in answerOptions">
</select>
</div>
</div>
I am wondering how I set the value of what is shown in the select statement. When the page loads, it should already be installed, because I go through the for loop to set the editing values of CurrentlySelectedAnswerOption so that each one is preselected (the index [$ index] refers to the ng-repeat index, which is inside because that there are several selections inside ng-repeat, I need one spot on ng-repeat in the array to track each individual selection), but instead it first appears as an empty space. I used the ng-init function, which is called whenever the button that displays the above div is pressed, and the function when the page loads. I used the bindings in the DOM and console.logs to check the values. They all seem correct.answerOptions in ng options:
var answerOptions = [
{ front: "RadioButton", back: "Multi-Choice" }
{ front: "CheckBox", back: "Multi-Answer" }
{ front: "TextBox", back: "Free Text" }
];
, CurrentlySelectedAnswerOption [$ index], , , - select . -, , ng-options ? - ?
UPDATE:
CurrentlySelectedAnswerOption :
this.scope.editingCurrentlySelectedAnswerOption = [];
for (var i in this.scope.currentTemplate.questions) {
if (this.scope.currentTemplate.questions.hasOwnProperty(i)) {
this.scope.editingCurrentlySelectedAnswerOption.push(this.scope.currentTemplate.questions[i].answerType);
}
}
, , . scope.currentTemplate - , html ng-repeat . .
this.scope.currentTemplate.questions [0]:
new Utilities.Question(
"Question1",
{ front: "TextBox", back: "Free Text" },
["Yes", "Maybe", "No", "I don't know"],
[50.0, 25.0, 0.0, -25.0]
)
Utilities.Question:
export class Question {
question: string;
answerType: any;
answerOptions: string[];
answerWeights: number[];
constructor(question?: string, answerType?: any, answerOptions?: string[], answerWeights?: number[]) {
this.question = question;
this.answerType = answerType;
this.answerOptions = answerOptions;
this.answerWeights = answerWeights;
}
}