0

Hi I want to combine the singleton data coming with http get with the model from the selection box.

$scope.ShowResult = function() {
  $http.get('http://otm.dev/carPrice?modelId=' + $scope.model_id).success(function(data) {

    var result = $filter('filter')(data, {
      kaskobedel_marka_id: $scope.model_id
    })[0];

    $scope.name = result.a;

  });
};

with

<select class="form-control" name="price" ng-model="year" ng-click="ShowResult()">
  <option value="">Select Year</option>
  <option value="a">2003</option>
  <option value="b">2004</option>
  <option value="c">2005</option>
  <option value="d">2006</option>
  <option value="e">2007</option>
  <option value="f">2008</option>
  <option value="g">2009</option>
  <option value="h">2010</option>
  <option value="i">2011</option>
  <option value="j">2012</option>
  <option value="k">2013</option>
  <option value="l">2014</option>
  <option value="m">2015</option>
  <option value="n">2016</option>
  <option value="o">2017</option>
</select>

The database is stored in years a, b, c That is, a = 2003, b = 2004, c = 2005. I need to merge the fetched data with the value from the selection box and get the data for that column. Please help me in my different combinations.

Here Fiddle

3
  • look at ng-options usage Commented Feb 20, 2017 at 7:58
  • your fiddle is not correct, please set it up with angular Commented Feb 20, 2017 at 8:04
  • How can I use the ng-options in this way according to the table according to the incoming data. json-generator.com/api/json/get/bPrBOrQqUO?indent=2 Commented Feb 20, 2017 at 8:29

2 Answers 2

0

Try this,

$scope.getData = function(){
   $http.get('http://otm.dev/carPrice?modelId='+$scope.model_id).success(function(data) {
       var result = $filter('filter')(data, {kaskobedel_marka_id:$scope.model_id})[0];
       $scope.data = result;
        }
    });
}
$scope.getData();
$scope.ShowResult = function () {
    $scope.name = $scope.data[$scope.year];
};
Sign up to request clarification or add additional context in comments.

Comments

0

Thanks to everyone, I solved it like this.

    $scope.getYear = function (model) {
    $http.get('http://otm.dev/carPrice?modelId='+$scope.model_id)
        .success(function(resp) {
            var result = $filter('filter')(resp, {kaskobedel_marka_id:$scope.model_id})[0];
            $scope.name = result[model];
        });
};

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.