Having trouble getting typeahead suggestions to display in Bootstrap UI when using AngularJS?

I am having trouble getting static suggestions to display in a search textbox. I have tried following the example at this link. Below is the code I am working with:

Here is my 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>

The controller code looks like this:

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

Answer №1

Make sure to check your browser console for any errors, as the code seems to be functioning correctly.

1. Ensure that all dependencies are included:

<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. Look for ng-app="angularTypeahead" in the HTML and:

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

3. Check for ng-controller="TypeaheadCtrl" and:

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

4. View the full code:

Experience a live demo of the complete code here

<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>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Navigating through a sequence of URLs in Node.js, one by one

I am new to node js and experimenting with creating a web scraping script. I've received permission from the site admin to scrape their products as long as I make less than 15 requests per minute. Initially, my script was requesting all URLs at once, ...

Understanding how to read a JSON response when the dataType is specifically set to JSONP

I am attempting to send a JSONP request for cross-domain functionality. The issue is that my server does not support JSONP requests and interprets them as regular JSON, responding with an object: {result: 1} Below is the AJAX request I have made: jQuery. ...

What's the best method for uploading a file to AWS S3: POST or PUT requests?

Could you please provide insights on the advantages and disadvantages of utilizing POST versus PUT requests for uploading a file to Amazon Web Services S3? Although I have come across some relevant discussions on platforms like StackOverflow, such as this ...

Is it possible to use the .map() method on an array with only 3 items and add 2 additional placeholders?

I need to iterate through an array of 5 items in a specific way: list.slice(0, 5).map((i) => { return <div>{i}</div> }); However, if the array only contains 3 items, I would like to add placeholders for the remaining 2 items in my reac ...

I encountered a Vue warning indicating an issue in the v-on handler: "Error: Request failed with status code 404"

I recently started learning Vue.js and attempted to follow a tutorial on integrating Axios. Unfortunately, I keep encountering an error that I can't seem to resolve. I initially ran it on localhost:3000, then switched back to 8080, but the issue persi ...

Navigational link behavior in the React component with the <tr> element

I am in the process of developing a React application with a component that shares a resemblance to the following: class TableRow extends React.Component { constructor(props) { super(props) } render() { const handleClick = () ...

Disabling JavaScript with InternetExplorerDriver in Selenium

Is there a way to turn off JavaScript when using the InternetExplorerDriver? I've tried the code below, but it doesn't appear to disable JavaScript: self.selenium = webdriver.Remote( command_executor="http://localhost:4444/wd/hub", desire ...

How to convert an array of keys and an array of values into an array of objects using JavaScript

My question is similar to the one found here: Merging keys array and values array into an object using JavaScript However, I am unable to find a solution for my specific scenario. If I have these two arrays: const keys = ['x', 'y', &ap ...

Learn the best practices for sharing .env values from the main project component to various reusable npm installed components

In recent projects I've worked on using React and Vue.js, I have utilized .env variables to store API URLs for micro services and other configuration settings that are used throughout the root project. However, when it comes to child components insta ...

Step by step guide on using PHP Curl to easily register a new user on an AngularJS website

Looking for assistance from someone knowledgeable in PHP and AngularJS to assist with parsing a registration page in order to create a Curl Function. I am currently working on establishing a Single Sign On feature with a partner website. Once users regist ...

Attaching to directive parameters

I've been working on creating a draggable div with the ability to bind its location for further use. I'm aiming to have multiple draggable elements on the page. Currently, I've implemented a 'dragable' attribute directive that allo ...

What is the best way to assign dynamic values for array destruction?

Is there a way for me to avoid manually writing out six lines by implementing a loop to retrieve all six values from one line instead? console.log(array[0].name.LINE1) console.log(array[0].name.LINE2) console.log(array[0].name.LINE3) console.log(array[1].n ...

tips for correctly importing source files into jasmine-node testing framework

Currently, I am utilizing the jasmine spec library in combination with the jasmine-node runner for node.js. My main query revolves around the correct method to execute tests using a command in the CLI that encompasses both source files and spec files. Wit ...

Tips for consuming a REST API to retrieve JSON data and assign it to a variable for use in React JS

I'm currently working on developing a shopping application using React.js. I found inspiration from a sample application on https://codepen.io/paulkim/pen/oZLavq , and now I am looking to fetch product information from an API call. I have attempted to ...

The JSON object array is not empty, but it is unable to be iterated using a foreach loop, displaying a

Exploring a library of books from a Firestore collection in the create() method. The book data is stored in an array called checkout which is initialized in the data() method. export default { name: "checkout-history", data() { return { che ...

Unable to save drag and drop elements in localStorage using angularjs

Greetings! I am currently working on a straightforward application that allows users to assign tasks through a drag and drop feature. This application utilizes the angular-dragdrop.min.js file. I have encountered an issue when storing data in local storag ...

Interpolating UV is not allowed: 'flat': Using a reserved word in an illegal manner

As a beginner, I recently learned that UV coordinates are not interpolated in WebGL, allowing for exact pixel values to be retrieved. However, when attempting to use the 'flat' keyword, I encountered an error. By adding 'flat' before t ...

Is there a way to bring together scrolling effects and mouse movement for a dynamic user

If you want to see a scrolling effect, check out this link here. For another animation on mouse move, click on this link(here). Combining both the scrolling effect and the image movement might seem challenging due to different styles used in each templat ...

Is pl/pgsql block code supported by postgres-nodejs?

I am attempting to define a custom UUID variable that can be utilized across multiple queries within a transaction. Initially, I attempted using a JavaScript variable which ultimately defeated the purpose of declaring the variable on the server side. The ...

Utilize React Chart.js to showcase Time values along the Y axis of a line chart

My goal is to showcase the values from this dataset on a React Chart.js line chart. The timestamps are in hours, minutes, and seconds format. { "totaltime": "10:55:41", "date": "2018-01-01T00:00:00" }, ...