anguljs select默认选中去除空格

写一个获取省市的下拉框,向后端请求数据,默认选中第一行

后端返回数据格式:

[{"id":1,"name":"广东"},{"id":2,"name":"河南"},{"id":3,"name":"河北"},{"id":4,"name":"陕西"},{"id":5,"name":"江苏"}]

 前端代码结构

<span>省市</span>
<select id="select-province" ng-model="provinces[0].id" ng-options='x.id as x.name for x  in provinces'>
</select>

 service代码

import angular from 'angular';

const MODULE_NAME = 'service';

export default angular.module(MODULE_NAME,[])
  .factory('getProvinces',function($http){
    return {
      getProvinces:getProvinces
    }

    function getProvinces(s){
      $http({
        method: 'POST',
        url:'networkMonitoring/getProvince',
        data: {}
      }).then(function(res){
        console.log(JSON.stringify(res.data));
        s.provinces=res.data;
      })
    }
  })
  .name;
原文地址:https://www.cnblogs.com/iagw/p/6710023.html