我有一个API来获取下拉列表和评分值的值。
1)我有一个UI,如下图所示。
2)代码如下:
<td>
<div class="">
<select ng-if="question.MasterDataCategoryId != null" id="answer{{question.QuestionId}}" ng-model="question.MasterData" ng-init="question.MasterData;" class="form-control" style="width: 300px; white-space:pre-wrap;">
<option selected="selected"></option>
<option ng-repeat="answer in answerData[question.MasterDataCategoryId]" value="{{answer.MasterData}}">{{answer.MasterData}}</option>
</select>
<input ng-if="question.MasterDataCategoryId == null" id="{{question.QuestionId}}" ng-model="question.MasterData" type="text" style="width: 300px;" name="question.QuestionId" class="form-control">
</div>
</td>
<td>
<div class="">
<span ng-if="question.MasterDataCategoryId != null">{{question.Score}}</span>
<select ng-if="question.MasterDataCategoryId == null" id="projectlist" class="form-control" required ng-model="scoring">
<option selected="selected"></option>
<option ng-repeat="score in scoringDetails" value="{{score.Score}}">
{{score.Score}}
</option>
</select>
</div>
</td>
根据下拉值,我需要动态显示我将在同一API中获得的评分。
任何让我知道如何实现这一点。
答案 0 :(得分:0)
您可以在所需的下拉列表中使用ng-change = "someFunction()"
。使用http GET
或POST
方法在该函数中调用您的API,如下所示 -
$http.get(url)
.then(function(response) {
console.log(JSON.stringify(response))
// set your scoring variable here
$scope.scoring = yourValue; // your value from response
}).error(function(error) {
console.log(JSON.stringify(error))
});
答案 1 :(得分:0)
在ng-change of dropdown中写下一个改变得分下拉值的功能。假设以下代码
在HTML中
<select ng-change="scoreChange()" ng-model="dropvalue">
<option></option>.....
</select>
<select ng-model="score">
<option></option>.....
</select>
在控制器
中$scope.scoreChange = function(){
$scope.score = desiredvalue;
//or you can call api and assign it here.
}