在 ng-repeat 和 ng-change 中传递两个值

pass two values in ng-repeat and ng-change

控制器:

var response = {
  "json": {
    "response": {
      "servicetype": "100",
      "functiontype": "101",
      "statuscode": "success",
      "data": [
        {
          "countryid": 1,
          "countryname": "India",
          "countrycode": "91",
          "currencyname": "Indian rupee",
          "currencycode": "INR",
          "latitude": "21.7679",
          "longitude": "78.8718"
        }
      ]
    }
  }
}

  $scope.country = response.json.response.data;

Html:

 <select name="Country" class="form-control1 drop countries" required  ng-model="model.country" placeholder="Select" value="India"  ng-change="getState(model.country);">
    <option value="" disabled selected> Country*</option>
    <option ng-repeat="item in country track by $index" value="{{item.countryid}}">{{item.countryname}}</option>
        </select>

我想通过 countryname 和 countryid 来获取州列表,需要解决方案。我只能通过国家 ID。需要帮助。

改用ng-options

 <select  ng-model="model.country" required
    ng-options="c.countryid as c.countryname for c in country" >
    <option value="">Country*</option>
</select>

它会给你输出:

<select ng-model="model.country" required="" 
       ng-options="c.countryid as c.countryname for c in country" 
       class="ng-pristine ng-invalid ng-invalid-required">
    <option value="" class="">Country*</option>
    <option value="0">India</option>
</select>

Demo Fillde


关于你的情况:track by $index 是你的 select

Demo Fillde 2

<select ng-model="country" required
    ng-options="c as c.countryname for c in country track by c.countryid" ng-change="getState(country.countryid, country.countryname);" >
    <option value="">Country*</option>
</select>

使用ng-options,您将获得国家/地区模型中的所有值