AngularJS 动态设置select的默认selected

遇到一个问题,在控制器里设置了stafftype的默认值

.controller('InfoStaffCtrl', function($scope, $rootScope, $state, $log,$ionicLoading, $timeout,Manpower) {

        //列表   
        $scope.search = {p:1,audittype:'',name:'',stafftype:'',companyname:''};
        $scope.staffTypes = ["请选择","飞行员","机务","航务","管理","空管","其他"];    
        $scope.doSearch = function(){
            ...
            //$scope.number = $scope.search.stafftype;
            ...
        }
        function loadData(){
            ...
        }
        loadData();

    })

然后根据选择stafftype的项进行loaddate,再点击搜索依然是默认的选项

经过搜索参考这两个链接1
2

添加angular的ng-selected

<label class="item item-input item-select">
          <span class="input-label">人员分类span>
          <select ng-model="search.stafftype">
            <option value="{{$index}}" ng-repeat="t in staffTypes" ng-selected="number==$index">{{t}}option>         
          select>
        label>

当搜索提交的stafftype值和页面里下拉选项value相等时,选中该值

PS:
更复杂的循环数据应该得搭配上ng-options吧,还没试过

你可能感兴趣的:(前端开发,angular)