【问题标题】:Bootstrap typeahead is not working with ng-modelBootstrap typeahead 不适用于 ng-model
【发布时间】:2015-10-21 12:41:17
【问题描述】:

我有一个文本框来指定国籍。为此,我正在使用 Bootstrap 预输入。

<input type="text" class="form-control" ng-model="nationality" placeholder="Enter Country" data-provide="typeahead" data-items="5" autocomplete="off" data-source='["Afghanistan","Australia","Bangladesh",
"Brazil","Britan","Canada","China","Denmark","Egypt","France",
"Germany","India","Indonesia","Iran","Iraq",
"Isrel","Italy","Japan","Nepal","Pakistan","Sri Lanka",
"United States","New Zealand","South Africa","Russia","South Korea","Sapin","Chilie","Sweeden"]'>

我将 ng-model 数据发布到控制器,就像任何其他文本框数据一样。弹出来选择国家,但国家名称不与 ng-model 绑定。我从键盘输入的字符是绑定的。

例如- 如果我输入 In,我可以选择 India,但只有 In 与 ng-model 绑定。

【问题讨论】:

    标签: angularjs twitter-bootstrap


    【解决方案1】:

    这样试试

    <input type="text" class="form-control" ng-model="nationality" placeholder="Enter Country" id="country" data-provide="typeahead" data-items="5" autocomplete="off">
    

    和js部分

    <script>
    
        var data = ["Afghanistan","Australia","Bangladesh",
        "Brazil","Britan","Canada","China","Denmark","Egypt","France",
        "Germany","India","Indonesia","Iran","Iraq",
        "Isrel","Italy","Japan","Nepal","Pakistan","Sri Lanka",
        "United States","New Zealand","South Africa","Russia","South Korea","Sapin","Chilie","Sweeden"];   
        $('#country').typeahead({source: data}) 
    
    </script>
    

    提前输入工作example

    【讨论】:

    • 这种方法的问题是一样的。 ng-model 是我从键盘输入的绑定字符,它没有从弹出窗口中获取所选国家/地区:(
    • 你是否包含了字体库??
    • 如果我包含typeahed js文件,typeahed(弹出)功能将消失。奇怪但真实。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-05
    • 1970-01-01
    相关资源
    最近更新 更多