0
我在AngularJS开发中相当新手。我正在研究一个项目,其中有一组输入表。我已经使用ng模型来计算一个基于另外两个的输入。 例如,我有一个学生对象,其中包含正确的,不正确的和未尝试的问题。对于很多学生,我使用ng-repeat
如下所示。但是,当我执行ng-model=some-expression
时,它在控制台中显示错误,表示该表达式不可分配。但它的工作。我很困惑,有什么方法可以解决这个问题。 感谢AngularJS ng模型的数学表达式
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: ''});
}
感谢做到这一点。但是我试过了,它并没有在视图上实时升级它? –
发布'studentData'数组 –
'[{“name”:“Akhilesh”,“batch”:“A1”,“correctPhysics”:12,“incorrectPhysics”:3,“unattemptedPhysics”:0,“correctChemistry”:0 “incorrectChemistry”:0 “unattemptedChemistry”:0 “correctMaths”:0 “incorrectMaths”:0 “unattemptedMaths”:0 “correctBio”:0 “incorrectBio”:0 “unattemptedBio”:0,”总数“:45}]' –