Unable to show outcomes utilizing angular-ui autocomplete

While attempting to incorporate something similar to the Google Map example from the angular-ui bootstrap demo page, I encountered an issue where the results were not displaying in the dropdown menu.

If you'd like to view the full code, you can visit: http://plnkr.co/edit/eIM7UC4HrIUXxdET3CO0?p=preview

This is what has been implemented so far:

HTML

<input required ng-model="asyncSelected" typeahead="address for address in getUserData($viewValue) | filter:$viewValue" type="text" placeholder="e.g John, David">

Angular controller

$scope.getUserData = function(val) {
            return $http.get('/sessionHandler/userProfileNameAndPicture/'+val, {
            }).then(function(userData){
              var addresses = [];
              console.log(userData); // see picture below 
              angular.forEach(userData.data, function(item){
                addresses.push(item);
              });
              return addresses;
            });
          };

Console.log(userData)

I am receiving the result back, but it's not displaying in the dropdown menu.

UPDATE: After applying the solution suggested by @Engineer

I encountered this error:

TypeError: Cannot call method 'replace' of undefined

Answer №1

Looking at the image, it is evident that there is no presence of the "results" property (which you are referencing in the .forEach function) within the data array. I recommend modifying your code as shown below:

angular.forEach(userData.data, function(item){
                         //  ^--------   '.results' has been removed

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

Error during minification process for file opentok.js at line 1310: react-scripts build

I encountered an error while trying to minify the code in my React project using npm run build. The snippet below seems to be the cause of the issue. Any suggestions on how I can resolve this problem? const createLogger = memoize(namespace => { /** ...

Leverage JSON data and implement it in JavaScript

In my PHP page, I have a JavaScript function that includes a JSON method for retrieving data from the database. The code snippet looks like this: $this->registerJsFile('/js/restaurant-reserve.js', ['depends' => [JqueryAsset::class ...

Is it feasible to create a self-contained HTML document that can interact with client serial ports through JavaScript?

Is it feasible to execute a client-hosted HTML file (including scripts) that can interact with the computer's serial ports? I'm looking for a portable 'applet' that can be used to configure a device connected via serial communication u ...

Testing with Phantom/Casper in a browser-based environment

Currently, I am utilizing Casper for UI testing on websites. My main concern is regarding the compatibility testing in various browsers such as IE, Chrome, and Firefox using Casper. If this cannot be achieved with Casper, I am open to alternative methods ...

Tips on executing a $.get request while submitting a form?

Instead of using AJAX to submit my form, I am trying to implement a progress bar by making GET requests to the server while the form is submitting. This is particularly important when dealing with multiple file uploads that may cause the submission to take ...

Facing issues connecting to my MongoDB database as I keep encountering the error message "Server Selection Timed Out After 3000ms" on MongoDB Compass

I am encountering an error on my terminal that says: { message: 'connect ECONNREFUSED 127.0.0.1:27017', name: 'MongooseServerSelectionError', reason: TopologyDescription { type: 'Single', setName: null, maxS ...

"Exploring the functionalities of Expressjs's bodyParser and connect-form

I am encountering issues when trying to upload images using a connect form. It seems that the bodyParser() is causing problems with the upload process. Conversely, if I do not use bodyParser, I am unable to upload files. How can I resolve this issue and ...

What's the best way to retrieve the dates for the current week using JavaScript?

Could anyone help me find a way to retrieve the first and last dates of the current week? For example, for this week, it would be from September 4th to September 10th. I encountered an issue at the end of the month when dates overlap two months (such as t ...

Utilize Optional Chaining for verifying null or undefined values

I have utilized the following code: data?.response[0]?.Transaction[0]?.UID; In this scenario, the Transaction key is not present, resulting in the error message: ERROR TypeError: Cannot read properties of undefined (reading '0') Instead of chec ...

Ways to make a button blink using AngularJS

Currently working on an AngularJS SPA application where a button is present in the front-end HTML page. When this button is clicked, it triggers an operation which takes some time to complete. I want to inform the user that the operation is still in prog ...

The issue with Firebase's real-time database is that data constantly gets overwritten within a single node

Having an issue with writing data to my Firebase realtime database. Below is the code I am using: firebase.database().ref("ac/0/").set(null); firebase.database().ref("ac/0/").once('value', function(snapshot){ for(var i=0; ...

Sliding with JavaScript

I'm looking to develop a unique web interface where users can divide a "timeline" into multiple segments. Start|-----------------------------|End ^flag one ^flag two Users should be able to add customizable flags and adjust their position ...

IE8 does not properly execute AJAX call to PHP file

It's strange, it works perfectly fine in Firefox. This is the JavaScript code I'm using: star.updateRating=function(v, listid) { xmlHttp=GetXmlHttpObject(); if (xmlHttp==null) { alert("Looks like AJAX isn't supported by your browser!" ...

There seems to be an issue with the AJAX REST call failing to transmit data

Whenever I attempt to submit the form, the page refreshes and nothing gets saved in the database. The code in subforum.js $(document).on('click','#submit',function(e) { var user = JSON.parse(sessionStorage.getItem("ulogovan")); consol ...

Show Random Section

Hey there! I'm currently working on randomizing the display of these divs on my homepage. The specific CSS I have in place is making it a bit tricky, so I haven't been able to implement any of the usual methods for randomizing images. Any suggest ...

Setting the second tab as the primary active tab

I am currently working on a script that is well-known, and everything is functioning perfectly. However, I want to change it so that when the page is first opened, it displays the second tab instead of the first one (the first tab being a mail compose tab ...

Reveal concealed content when a responsive table becomes scrollable on a mobile device

I recently completed a project that was overloaded with tables. I made all the tables responsive, but they still take vertical scroll if they don't fit on certain devices due to their varying widths. For instance, Table A requires vertical scroll o ...

Hide a division when either the body or another division is clicked

<div id="container"> <div class='sub1'></div> <div class='sub2'></div> <div class='part1'></div> <div class='part2'></div> </div> When yo ...

When utilizing AngularJs in combination with the app manifest, the default state fails to load

I've been experimenting with App Manifest on my Android device in conjunction with my AngularJS/Ui-router application, and I'm encountering some unexpected behavior. Upon starting the WebApp, it initially loads index.html but does not activate t ...

Do commas at the end of JSON objects pose a risk of breaking

After diving into the proposed JavaScript features, one that caught my attention is the idea of supporting trailing commas in object literals and arrays. When it comes to parameters, trailing commas are not relevant, so let's put that aside for now. ...