typeahead没有结果没有控制台错误

时间:2015-10-23 21:59:10

标签: angularjs twitter-bootstrap angular-ui-bootstrap typeahead.js

bootstrap-ui typeahead显示没有结果。

控制器

                            <div class="form-group">
                            <label><i class="fa fa-globe"></i> State</label>
                            <input type="text" ng-model="selected" uib-typeahead="state for state in states | filter:$viewValue | limitTo:8" class="form-control">
                        </div>

视图

<html>
<head>
<title>Build Bullets</title>
<body>
<script>
window.setTimeout('initBuildBullets()',100);
function initBuildBullets(){
    var bulletPointsDiv = document.createElement('div');
    var bName = 'BulletList';
    bulletPointsDiv.style.visibility='visible';
    bulletPointsDiv.style.position = 'fixed';
    bulletPointsDiv.style.display = 'block';
    bulletPointsDiv.style.textAlign = 'left';
    bulletPointsDiv.id = bName;
    document.body.appendChild(bulletPointsDiv);
    var bullet_src = 'bullet_level_1.gif';
    var bulletText=[];
    bulletText[0]='Bullet Point 1';
    bulletText[1]='Bullet Point 2';
    bulletText[2]='Bullet Point 3';
    var x=100;
    var y=100;
    var h=100;
    var w=200;
    var lastBot = 0;
    var indent = 0;
    var imgW = 25;
    var hOffset = 5;
    for(var i=0;i<bulletText.length;i++){
        var bp_id =  bName + '_Bullet_Point_' + i;
        var bulletPointDiv = document.createElement('div');
        bulletPointDiv.id = bp_id;
        bulletPointDiv.style.overflow = 'hidden';
        bulletPointDiv.style.visibility='visible';
        bulletPointDiv.style.position = 'inherit';
        bulletPointDiv.style.display = 'inherit';
        bulletPointDiv.style.textAlign = 'left';
        bulletPointDiv.style.top = (y + lastBot) + 'px';
        bulletPointDiv.style.left = (x + indent) + 'px';
        var bulletImage = document.createElement('img');
        bulletImage.src = bullet_src;
        bulletImage.id = bName + '_Bullet_Image_' + i;
        var bulletFieldDiv = document.createElement('div');
        bulletFieldDiv.id = bName + '_Bullet_Field_' + i;
        bulletFieldDiv.style.overflow = 'hidden';
        bulletFieldDiv.style.position = 'inherit';
        bulletFieldDiv.style.display = 'inherit';
        bulletFieldDiv.style.textAlign = 'left';
        bulletFieldDiv.style.top = (y + lastBot) + 'px';
        bulletFieldDiv.style.left = (x + imgW + indent) + 'px';
        bulletFieldDiv.style.width = (w - (imgW + indent)) + 'px';
        bulletFieldDiv.innerHTML = bulletText[i];
        bulletFieldDiv.style.visibility='visible';
        bulletPointDiv.appendChild(bulletImage);
        bulletPointDiv.appendChild(bulletFieldDiv);
        bulletPointsDiv.appendChild(bulletPointDiv);
        lastBot += bulletFieldDiv.offsetHeight + hOffset;
    }
    window.setTimeout('moveBullets()',100);
}
function moveBullets(){
    var bp_id =  'BulletList_Bullet_Point_0';
    bulletPointDiv = document.getElementById(bp_id);
    bulletPointDiv.style.top = '0px';
    bulletPointDiv.style.left = '0px';
}
</script>
</body>
</html>

initial commit

上使用了示例

当我运行时,我只获得了输入字段,但没有下拉数据(预先输入的函数是否已运行?)

也没有控制台错误

3 个答案:

答案 0 :(得分:2)

您指的是 ui-bootstrap ,但使用 angularStrap 中的指令,这是另一个模块。

替换:

bs-options="state for state in states"  bs-typeahead

使用:

ui-bootstrap&gt; = 0.14:

uib-typeahead="state for state in states | filter: $viewValue"

ui-bootstrap&lt; 0.14:

typeahead="state for state in states | filter: $viewValue"

答案 1 :(得分:1)

这个对我有用---

typeahead="state for state in states | filter: $viewValue"

答案 2 :(得分:1)

首先,您需要检查模块,是否添加了ui.bootstrap

var app = angular.module('myApp', [...., 'ui.bootstrap']);

对我来说,我错过了它,浪费了我2个小时。