desmanda
desmanda

Reputation: 23

typeahead not showing suggestions with bootstrap UI and angularjs

I want to display a static suggestions in a search textbox but nothing is displayed. I am following this https://codepen.io/joe-watkins/pen/EagEWv. Here is my code.

HTML code:

 <div>    
    <input type="text" name="questions" id="questionss" class="form-control select2-search search_query" placeholder="what are you looking for ?" ng-model='myquery' typeahead="question for question in questions | filter:$viewValue | limitTo:3" />

    <div class="form-group">
        <button type="button" class="btn btn-primary" ng-click="search()">
          Get an answer ! <i class="fa fa-search"></i>
        </button> 
    </div>

And my controller:

var Questions=["hello","hi","question1","question2","question2"];
$scope.questions=Questions;

Upvotes: 0

Views: 376

Answers (1)

Yin Gang
Yin Gang

Reputation: 1443

Check if any error in your browser console, as your code is really working.

1.Make sure you have include all the dependence:

<link rel="stylesheet prefetch" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script>
<script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.12.0.js"></script>

2.Notice ng-app="angularTypeahead" in the html and:

var myApp = angular.module("angularTypeahead", ["ui.bootstrap"]);

3.Notice ng-controller="TypeaheadCtrl" and:

myApp.controller("TypeaheadCtrl", function($scope) {...});

4.Full code:

Here is a full code live demo

<html>
    <head>
      <link rel="stylesheet prefetch" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
      <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script>
      <script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.12.0.js"></script>
    </head>
    
    <body>
      <div ng-app="angularTypeahead">
        <div class="container-fluid" ng-controller="TypeaheadCtrl">
    
          <label for="states">Search for Answer</label>
          <input type="text" name="questions" id="questionss" class="form-control select2-search search_query" placeholder="what are you looking for ?" ng-model='myquery' typeahead="question for question in questions | filter:$viewValue | limitTo:3">
    
          <div class="form-group">
            <button type="button" class="btn btn-primary" ng-click="search()">
              Get an answer ! <i class="fa fa-search"></i>
            </button>
          </div>
    
    
        </div>
      </div>
      <script type="text/javascript">
        var myApp = angular.module("angularTypeahead", ["ui.bootstrap"]);
    
    
        // setup controller and pass data source
        myApp.controller("TypeaheadCtrl", function($scope) {
    
          var Questions = ["hello", "hi", "question1", "question2", "question2"];
          $scope.questions = Questions;
    
        });
      </script>
    </body>
    
    </html>

Upvotes: 1

Related Questions