【问题标题】:Get selected value with Angular bootstrap's TYPEAHEAD plugin and ng-change使用 Angular bootstrap 的 TYPEAHEAD 插件和 ng-change 获取选定的值
【发布时间】:2014-12-01 10:27:30
【问题描述】:

为什么我无法使用 ng-change 函数正确获取选定的预输入值?

这是我的代码

<input 
   type="text" 
   ng-model="asyncSelected" 
   placeholder="Locations loaded via $http"
   typeahead="address for address in getLocation($viewValue)" 
   typeahead-loading="loadingLocations" 
   class="form-control" 
   ng-change="change(asyncSelected)">

问题是变量 asyncSelected 总是返回我输入的字符串,而不是通过预先输入选择的字符串。这是向您展示问题的 plunkr,只需输入即可。我从 angular-ui-bootstrap 的官方文档中分叉它

PLUNKR LINK HERE

【问题讨论】:

    标签: javascript angularjs twitter-bootstrap angular-ui-bootstrap


    【解决方案1】:

    您可以使用 typeahead-on-select 属性在选择值时调用函数。试试这个:

    <input type="text" 
      ng-model="asyncSelected" 
      placeholder="Locations loaded via $http" 
      typeahead="address for address in getLocation($viewValue)" 
      typeahead-loading="loadingLocations" 
      class="form-control" 
      typeahead-on-select="change(asyncSelected)">
    

    【讨论】:

    • 啊..我错过了!!谢谢你。我花了一个小时才成功
    猜你喜欢
    • 2017-09-24
    • 1970-01-01
    • 2014-12-24
    • 2018-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-07
    相关资源
    最近更新 更多