本文介绍了在自动完成与角typehead的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一个自动完成的角度与typehead,但它不工作。

I tried to do an autocomplete in angular with typehead, but it is not working.

我下载了typehead.js从angularstrap页面。

I downloaded the typehead.js from angularstrap page.

的javascript:

myApp.controller('myCtrl', ['$scope', 'myservice', function ($scope, myservice) {
    $scope.counter = 0;
    $scope.name= [];
    myservice.getData().then(function (msg) {
        $scope.name= msg.data.names;
    });

    $scope.input = "";

}]);

HTML:

 <div ng-controller="myCtrl">
    <input type="text" class="form-control" ng-model="input" 
      bs-options="name for name in names" bs-typeahead>

 </div>

我做了什么错?

如果有对自动完成例如一个更好的解决方案请告诉我。
THX提前

If there is a better solution for autocomplete example pls tell me.thx in advance

推荐答案

$ scope.name $ scope.names 如果你想让它与您正在使用 BS-选项除权pression工作。例如:

Your $scope.name should be $scope.names if you want it to work with the expression you are using in bs-options. Eg

myApp.controller('myCtrl', ['$scope', 'myservice', function ($scope, myservice) {
    $scope.counter = 0;
    $scope.names= [];
    myservice.getData().then(function (msg) {
        $scope.names= msg.data.names;
    });

    $scope.input = "";

}]);

我创建了一个例如plunker显示您的code工作与修订以上。

这篇关于在自动完成与角typehead的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!