1

Hi I have following data

var myApp = angular.module('myApp', [])
    .controller('TestController', ['$scope', function ($scope) {
        $scope.data = [{"city":"New York","location":"123", "sales" :"233.00"},
                {"city":"Chicago","location":"953", "sales":"455"}'
                {"city":"New York","location":"788",  "sales" :"23432.23"},
                {"city":"Chicago","location":"853"}];

  $scope.update=function(location){

  };
}]);   

In my html I have

  <td>
    <select ng-model="item.location" ng-options="c.location as c.city for c in data" 
     ng-change="update(c.location)"></select>
  </td>
  <td>
    <div>
      <span ng-model="item.sales">{{sales }} </span>
    </div>
  </td>

I am trying to call update function from selected value of drop down and based on the item selected I want to update the value of sale using span. I am not sure how to accomplish that part. Please let me know how to go about it. Thanks

1 Answer 1

1

You don't even need your update function, just use data-binding. Change your ng-options like this to bind the whole object instead of just a field location :

ng-options="c as c.city for c in data"

To display the sales, just do this:

<span>{{ item.location.sales }} </span>

DEMO

Sign up to request clarification or add additional context in comments.

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.