AngularJS:ng更改后,第一个选择变为空

AngularJS:ng更改后,第一个选择变为空,angularjs,angularjs-ng-repeat,Angularjs,Angularjs Ng Repeat,我使用以下代码从本地json文件获取数据,并填充其中的两个下拉列表,但在ng change事件触发后,第一个下拉列表为空 $http({method: 'GET', url: 'data/local.json'}). success(function(data, status, headers, config) { // this callback will be called asynchronously // when t

我使用以下代码从本地json文件获取数据,并填充其中的两个下拉列表,但在ng change事件触发后,第一个下拉列表为空

   $http({method: 'GET', url: 'data/local.json'}).
        success(function(data, status, headers, config) {
            // this callback will be called asynchronously
            // when the response is available

      var _data=data;
      $scope.places=[];
      $scope.toPlaces=[];
      $scope.places=data;
      $scope.getToPlaces=function(){
      var selected=$('#fromSelect :selected').val();
      console.log($scope.places[1]);
      var key=$scope.places[1]
      $scope.toPlaces = _data[key].to;               
    }                 
    }).
    error(function(data, status, headers, config) {
        // called asynchronously if an error occurs
        // or server returns response with an error status.
        alert("failure");
    });
我正在使用这个链接中的代码:并从本地机器传递json文件

ng更改后,第一选择变为空

问题出在您的标记中: 发件人:

选择菜单中的项目时,所选选项表示的数组元素或对象属性将绑定到ngModel指令标识的模型

这就是为什么选中它时它会覆盖places数组的原因

select标记中的
ngModel
指令应仅引用作用域上的另一个变量:

<select ng-model="selectedPlace" ng-change="getToPlaces()" id="fromSelect">
    <option value="">--Please select From place</option>
    <option ng-repeat="p in places" value="{{p.id}}">
        {{p.name}}
    </option>
</select>

请发一张便条。我正在使用此链接,在home.js中,我有我的下拉代码。此plunker不有用,请提供appfor日期选择框的plunker。它在repeater中抛出重复键的错误。如何解决此问题?请尝试以下操作:
var selected = $scope.selectedPlace;