Using an AngularJS array with ng-repeat

As soon as a websocket message is received, the code below executes:

connection.onmessage = function (eventInfo) {
var onConnectionMessage = JSON.parse(eventInfo.data);

if (onConnectionMessage.messageType === "newRequest") {
    getQuizRequests();
}
}

The function getQuizRequests() looks like this:

function getQuizRequests() {
var URL = '/acceptOrReject/' + lookUpCode();

$http.get(URL)
    .success(function (data) {
        for (var i = 0; i < data.teamArray.length; i++) {
            teamArray[0] = data.teamArray[i];
        }
    })
    .error(function (data, status) {
        alert("ERROR data cant be loaded");
    });
 }

I have an array called teamArray that I want to use in an ng-repeat. How can I pass this filled array to where I'm using ng-repeat in my code?

Answer №1

Assuming that all the code is contained within a single controller

$scope.memberList = [];

function retrieveTeamData() {
    var requestURL = '/acceptOrReject/' + getCode();

    $http.get(requestURL)
    .success(function (response) {
        for (var i = 0; i < response.memberList.length; i++) {
            $scope.memberList.push(response.memberList[i]);
        }
    })
    .error(function (response, status) {
            alert("ERROR: Unable to load data");
    });
}

Afterward, in your HTML file:

<ul ng-show="memberList.length > 0" ng-repeat="person in memberList">
    <li>{{person}}</li>
</ul>

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

Unintentional occurrence of NilClass within my instance variables

Currently, I am in the process of creating a dating simulator. A crucial aspect of this simulation is keeping track of the relationships between characters. In this particular scenario, any character can date any other character, and there are two key vari ...

Is there a way to extract a token from the URL in a Nextjs/React application?

I am currently developing a project that relies heavily on API integration. My front-end interface is built using React and Next.js, while the back-end API is developed with Laravel. Within my front-end page, I have implemented a token in the URL to help ...

Tips for resolving routing problems in Angular 7 and MVC

I've encountered an issue with routing in my Angular app embedded within MVC. The routes defined in my ts file are as follows: const routes: Routes = [ { path: '', redirectTo: '/Listing/Listings', pathMatch: ' ...

Limit the 'contenteditable' attribute in table data to accept only integers

I have a question regarding editing table data row. Is there a way to restrict it to only integers? Thank you for your assistance! <td contenteditable="true" class="product_rate"></td> ...

Use jQuery to insert the TEXT heading as an input value

Can anyone help me with copying text from a heading to an input value? Here's an example: <h2 class="customTitleHead">This is a Heading</h2> I want to transfer the text from the heading into an input field like this: <input type="tex ...

Creating unique random shapes within a larger shape on a canvas, as shown in the image

I have a parent rectangle and would like to add up to 10 or fewer rectangles on the right-hand side corner of the parent rectangle, as shown in the image below: I attempted to write code to achieve this, but the alignment is off-center from the parent rec ...

What is the best way to style output in jQuery for a specific div?

I have developed a tool for creating forms, but I am struggling to format the output neatly like pretty print. I have tried using \n and pre tags as well. allCont += "<label>"+insCleaned+"</label><input type='text' name= ...

What is the TypeScript syntax for indicating multiple generic types for a variable?

Currently working on transitioning one of my projects from JavaScript to TypeScript, however I've hit a roadblock when it comes to type annotation. I have an interface called Serializer and a class that merges these interfaces as shown below: interfa ...

Tips for updating a nested MongoDB object

Looking to implement a reporting feature for my application When making a PUT request in the front end: .put(`http://localhost:3000/api/posts/report`, { params: { id: mongoId, ...

Generating a Personalized XML Format Using Information from a Single MySQL Table Row by Row

If anyone can assist with this, I would greatly appreciate it: <warehouse> <frontbay> </frontbay> <bayrow> <bay> </bay> <bay> ...

Tips for avoiding Netlify's error treatment of warnings due to process.env.CI being set to true

Recently, I encountered an issue with deploying new projects on Netlify. After reviewing the logs, I noticed a message that had never appeared during previous successful deployments: The build failed while treating warnings as errors due to process.env.CI ...

Searching through directories and creating an array in PHP

I attempted to scan the directory https://equestria.space/videosmlp/fim/ using PHP in order to find .mp4 files. After scanning and printing, I tried implementing it into index.php. <?php $dir = "../videosmlp/fim"; $scans = scandir($dir); $episo ...

Heroku is showing an Error R10 (Boot timeout) message, indicating that the web process was unable to bind to the designated $PORT within one minute of launching

Encountering an error while trying to deploy my first node project on Heroku. Here is the error message: 2020-09-29T04:24:09.365962+00:00 app[web.1]: production 2020-09-29T04:24:09.415266+00:00 app[web.1]: server is listening at port 40890 2020-09-29T04:24 ...

Exploring AngularJS: A Guide to Accessing Objects within Directives

I have successfully passed an object from the controller to the directive. However, when trying to access the object within the directive, it seems to be read as a string. Below is the code snippet, and I am trying to extract the City and State from the ...

Is it possible to conduct a feature test to verify the limitations of HTML5 audio on

Is there a way to detect if volume control of HTML5 audio elements is possible on iOS devices? I want to remove UI elements related to the volume if it's not alterable. After referring to: http://developer.apple.com/library/safari/#documentation/Aud ...

Is there a way to remove a value from the search bar while updating the table at the same time?

Although I can successfully search the table based on the values in my search bar, I am having trouble with updating the state when deleting a value. To see my code in action, check out my sandbox here. ...

Having trouble with submitting an HTML form using JavaScript and PHP

My webpage has an HTML form that sends data to a PHP file for processing. One issue I'm facing is with a dynamically generated combo box that works fine when the page loads, but the selected value is not being passed when the form is submitted. The J ...

What is the best way to pinpoint a specific Highcharts path element?

I am currently working on drawing paths over a graph, and I am looking to dynamically change their color upon hovering over another element on the page - specifically, a list of data points displayed in a div located on the right side of my webpage. Below ...

Angular Controller issue: 'MainCtrl' variable is not recognized as a function, it is showing as undefined

Out of the blue this afternoon, I encountered a puzzling AngularJS error: Argument 'MainCtrl' is not a function, got undefined While my Chrome browser still runs smoothly without any issues, I am struggling to identify the differences that cause ...

Testing the performance of MEAN applications under heavy load

As I work on developing an application using the cutting-edge MEAN stack, I have successfully deployed the initial version to a server. This application comprises of a static HTML file (along with CSS and some images) as well as numerous JavaScript files. ...