鍍金池/ 問(wèn)答/HTML5  HTML/ angular 中 select設(shè)置默認(rèn)值

angular 中 select設(shè)置默認(rèn)值

一直有點(diǎn)迷糊angular中的select的使用,給select設(shè)置默認(rèn)值,有的時(shí)候是好的,有的時(shí)候則不行,
具體代碼如下,希望誰(shuí)能給我分析講解一下

<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: "購(gòu)物相關(guān)" 
    }, { 
      questionTypeKey: "2", questionTypeName: "訂單相關(guān)" 
    }, { 
      questionTypeKey: "3", questionTypeName: "售后相關(guān)" 
    }, { 
      questionTypeKey: "4", questionTypeName: "定制相關(guān)" 
    }, { 
      questionTypeKey: "5", questionTypeName: "其他" 
    }],
    init(){
      this.getData();
    },
    getData() {
    },
    publish(){
      console.log(this.listItem)
    }
  }

clipboard.png

回答
編輯回答
祈歡

clipboard.png
運(yùn)行了下你的代碼 沒(méi)什么問(wèn)題 應(yīng)該是其他地方對(duì)數(shù)據(jù)進(jìn)行了操作導(dǎo)致的?

2017年2月26日 21:34
編輯回答
小眼睛

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

2017年3月1日 02:23
編輯回答
負(fù)我心

采用ng-selected,即可
https://gitee.com/shunzizhan/...

2018年2月20日 06:18