如果值匹配,则应自动选择选项
<input type ="text" class="form-control emailidinsert" dir-paginate="emails in emailarr | itemsPerPage:constidinfo.itemsPerPage" current-page="constidinfo.currentPage" total-items="total_count" value="{{emails.email_ids}}" >
这是我的文本字段,它具有用户电子邮件的值。
<select id="editunameto" class="form-control select" role="combobox" aria-haspopup="true" aria-expanded="false" tabindex="0" aria-labelledby="select2-supplier_id-container" ng-options='unames as unames.email_id for emails in emailarr'>
<option value="0">--Select Username--</option>
<option ng-repeat="unames in usernames" value="{{unames.email_id}}">{{unames.username}}</option>
</select>
这是我的选择框想要自动选择输入类型文本中的选项值,因为值应与选择选项值匹配.. 我如何实现我尝试使用 ng-options 但没有使用
请尝试以下代码,并查看此 plunker 链接以获取您的示例工作场景。
控制器:
$scope.emailarr = [{
username: 'username1',
email_ids: 'email_Id1'
},{
username: 'username2',
email_ids: 'email_Id2'
},{
username: 'username3',
email_ids: 'email_Id3'
},{
username: 'username4',
email_ids: 'email_Id4'
},{
username: 'username5',
email_ids: 'email_Id5'
}];
模板:
<input type ="text" ng-model="emails.email_ids"/>
<select ng-model='emails.email_ids' ng-options='emails.username as emails.email_ids for emails in emailarr'>
<option value="">--Select Username--</option>
</select>