【问题标题】:Dynamic default value to be selected from select dropdown in angularjs view page要从 angularjs 视图页面中的选择下拉列表中选择的动态默认值
【发布时间】:2018-10-18 07:41:38
【问题描述】:

如果值匹配,则应自动选择选择选项

<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 但没有用

【问题讨论】:

  • 您的控件中似乎缺少 ng-model 以将值绑定到 angularjs 元素。
  • @ImmanuelKirubaharanS 我在 select 中添加了 ng-model="usernames.email_id" ng-options='unames.email_id for unames in emailarr.email_ids' 但也没有显示

标签: php angularjs codeigniter angularjs-ng-repeat angularjs-ng-options


【解决方案1】:

请尝试以下代码,并检查this plunker link 以获取您的示例工作场景。

控制器:

$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>

【讨论】:

  • 选择来自其他查询的下拉值和来自其他查询的动态默认选择值,因此选择框有两个 $scope.usernames,其中包含用户名以及 emailid 和 $scope.emailarr,其中包含 emailid
  • 我认为更改范围名称就足够了。我已经根据你上面的描述更新了我的plunker,请查看我的updated plunker
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多