【发布时间】:2017-05-29 15:38:48
【问题描述】:
我是 AngularJS 开发的新手。我正在做一个项目,其中我有一个包含一组输入的表。我已经使用 ng-model 根据其他两个输入来计算一个输入。
例如,我有一个学生对象,其中包含正确、不正确和未尝试的问题作为键。对于许多学生,我使用ng-repeat,如下所示。但是,当我执行ng-model=some-expression 时,它会在控制台中打印一个错误,说明该表达式是不可赋值的。但它有效。我很困惑有没有办法解决这个问题。
谢谢
HTML:
<tr ng-repeat="student in studentData">
<td>{{ student.name }}</td>
<div ng-show="selectedSubj.indexOf('Physics') > -1">
<td><input type="number" min="0" ng-model="student.correctPhysics" required>
<input type="number" min="0" ng-model="student.incorrectPhysics" required>
<input type="number" min="0" ng-model="student.unattemptedPhysics=noOfQues-student.correctPhysics-student.incorrectPhysics"></td>
</div>
</tr>
控制器代码:
$scope.studentData = ['Akhilesh'];
for(var i = 0; i < $scope.selectedStudents.length; i++){
$scope.studentData.push({name: $scope.selectedStudents[i].name, batch: $scope.selectedStudents[i].batch,
correctPhysics: 0, incorrectPhysics: 0, unattemptedPhysics: 0,
correctChemistry: 0, incorrectChemistry: 0, unattemptedChemistry: 0,
correctMaths: 0, incorrectMaths: 0, unattemptedMaths: 0,
correctBio: 0, incorrectBio: 0, unattemptedBio: 0, total: ''});
}
【问题讨论】:
标签: javascript angularjs