2017-12-05 1 views
1

Ich habe eine API, um den Wert für Dropdown-und Scoring-Wert zu erhalten.Wie hole ich den Wert von einer API basierend auf dem Wert des ausgewählten Feldes?

API screenshot

1) Ich habe eine Benutzeroberfläche, die wie unten Screenshot aussieht.

UI screenshot

2)-Code wird im Folgenden aufgeführt sind:

<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> 

Basierend auf dem Drop-Down-Wert Ich muss dynamisch den Torreigen zeigen, die ich in der gleichen API bekommen.

Kann mir jemand wissen, wie man dies erreicht.

Antwort

0

Sie ng-change = "someFunction()" auf das gewünschte Dropdown verwenden können & rufen Sie Ihre API in dieser Funktion http GET oder POST Verfahren wie folgt verwendet -

$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)) 
    }); 
0

In ng-Wechsel Dropdown eine fucntion schreiben, die die Partitur Drop-Down-Wert ändert. Angenommen, der follwing Code

In HTML

<select ng-change="scoreChange()" ng-model="dropvalue"> 
    <option></option>..... 
</select> 

<select ng-model="score"> 
    <option></option>..... 
</select> 

Kontroller

$scope.scoreChange = function(){ 
    $scope.score = desiredvalue; 
    //or you can call api and assign it here. 
} 
Verwandte Themen