angular 中 select设置默认值

一直有点迷糊angular中的select的使用,给select设置默认值,有的时候是好的,有的时候则不行,
具体代码如下,希望谁能给我分析讲解一下

<select class="input-sm form-control w-sm inline v-middle" ng-model="questionModObj.listItem.questionTypeKey">
    <option ng-repeat='item in questionModObj.typeList' value="{{item.questionTypeKey}}">{{item.questionTypeName}}</option>
</select>
$scope.questionModObj = {
    listItem:{
      questionId:$state.params.id,
      questionTypeKey:"2",
      questionDesc:"",
      questionHtml:''
    },
    typeList: [{ 
      questionTypeKey: "0", questionTypeName: "全部" 
    }, { 
      questionTypeKey: "1", questionTypeName: "购物相关" 
    }, { 
      questionTypeKey: "2", questionTypeName: "订单相关" 
    }, { 
      questionTypeKey: "3", questionTypeName: "售后相关" 
    }, { 
      questionTypeKey: "4", questionTypeName: "定制相关" 
    }, { 
      questionTypeKey: "5", questionTypeName: "其他" 
    }],
    init(){
      this.getData();
    },
    getData() {
    },
    publish(){
      console.log(this.listItem)
    }
  }

clipboard.png

阅读 4.9k
3 个回答

用ng-options吧,<select ng-options=''></select>

clipboard.png
运行了下你的代码 没什么问题 应该是其他地方对数据进行了操作导致的?

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进