Angular Table with Loading Bar

Hey there, here's the JSON data I have:

[
    {
        "name": "AAAAAA",
        "loading": "False",
    },
    {
        "name": "BBBBBB",
        "loading": "45%",
    },
    {
        "name": "CCCCCC",
        "loading": "12%",
    },
    {
        "name": "DDDDDD",
        "loading": "False",
    }
]

This is my JavaScript code:

var app = angular.module('app', []);
    app.service('service', function($http, $q){
        var deferred = $q.defer();

        $http.get('names.json').then(function(data){
            deferred.resolve(data);
        });

        this.getNames = function() {
            return deferred.promise;
        }
    });
    app.controller('FirstCtrl', function($scope, service, $http) {
        var promise = service.getNames();
        promise.then(function (data) {
            $scope.names = data.data;
            console.log($scope.names);
        }
    );

In HTML, it looks like this:

<tbody>
    <tr ng-repeat="name in names">
        <td>{{name.name}}</td>
        <td>{{name.loading}}</td>
    </tr>
</tbody>

The goal is to create a loading bar for the "loading" percentage. The value is retrieved from the server and represents the progress of something being loaded. The percentage increases over time until it reaches 100%, then it changes to "False". When the value is in percentage form, display a loading bar in the table cell; when it's "False", simply show "False" in the table. Appreciate any help on this matter. Thanks!

Answer №1

Utilize the progress element in HTML5 for displaying progress.

To incorporate this feature, adjust your code as shown below:

<td><progress value="{{name.loading}}" max="100" ng-if="name.loading != 'False'">{{name.loading}} %</progress></td>

Answer №2

To make this work, you can utilize the ngIf directive.

<tbody>
    <tr ng-repeat="person in people">
        <td>{{person.name}}</td>
        <td ng-if="person.loading !== 'False'">{{person.loading}}</td>
    </tr>
</tbody>

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

After submitting the form, React checkboxes fail to reset their state

Being a relative newcomer to React, I embarked on creating a skincare app as a project to enhance my understanding. In designing the app, I incorporated a form for product registration which includes checkboxes. My current dilemma revolves around clearing ...

creating dynamic parameterized URLs in Laravel

For example: Here are a few names. - Mujib - Amjed - Anees When someone clicks on "Mujib," the URL should remain the same and only the parameter should change. When someone clicks on "Amjed," the URL parameter should change to . ...

Prevent the function from being triggered repeatedly while scrolling

When a user scrolls to the bottom of the page, the following code is meant to load the next page. However, there are instances where it repeats itself due to rapid scrolling or while the AJAX content is still loading. Is there a way to prevent this code f ...

Unable to transfer object from Angular service to controller

I am currently utilizing a service to make a $http.get request for my object and then transfer it to my controller. Although the custom service (getService) successfully retrieves the data object and saves it in the responseObj.Announcement variable when ...

Ways to efficiently handle numerous asynchronous requests in a NodeJS/Express API

I am looking to consolidate a variety of REST APIs into a single, easy-to-use API. My plan is to develop a straightforward nodejs/express API that will handle the individual calls asynchronously and then aggregate all the results together at once. The Jav ...

Tips for transforming user inputs in HTML format into text within a prompt box

Is there a way to create a text prompt box for the user to input their name without risking the insertion of HTML elements into the page? I want to avoid any potential issues like inadvertently creating a new HTML element instead of displaying the intended ...

Which is the better option for data storage: JSON files or MySQL database?

I am currently developing a project that utilizes the vis.js JavaScript framework to showcase a visual network of various categories. There are approximately 2000 categories available for selection, each with a substantial amount of associated data. I am ...

Creating a dynamic bar chart using PHP variables

Is there a way I can dynamically display values on a flot bar chart using my PHP variables? For instance, instead of hardcoding the values like this: var data = [ [0, 11], //London, UK [1, 15], //New York, USA [2, 25], //New Delhi, India [3, 24], //Ta ...

Incantation within ng-include | src involving a series of characters

Is there a way to create a URL in ng-include|src by combining an expression and a constant string? I've attempted the code below, but it doesn't seem to be working. <aside ng-include src="{{staticPath}} + 'assets/tpl/products-feed-histor ...

In Vue, props are not automatically assigned; be sure to avoid directly mutating a prop when assigning it manually to prevent errors

I am working with two Vue components: GetAnimal.vue and DisplayAnimal.vue. GetAnimal.vue sends a JSON object containing animal data to DisplayAnimal.vue using router push. DisplayAnimal.vue then displays this data. The process flow is as follows: I navigat ...

Occasional TypeError when receiving JSONP response using jQuery .ajax()

Occasionally, I encounter an error message stating Uncaught TypeError: undefined is not a function when processing the JSONP response from my jQuery .ajax() call. The JSON is returned successfully, but sometimes this error occurs during the reading process ...

Navigate to a different webpage: Node.js

I've tried numerous solutions listed here, but being new to node.js, I seem to be missing a crucial part in my code. Can someone please assist me in identifying and resolving the issue? When the login button is clicked, my objective is to redirect the ...

displaying a confirmation alert upon unchecking a checkbox using javascript

I am trying to implement a feature where a message saying "are you sure?" pops up when the user tries to uncheck a checkbox. If they choose "yes", then the checkbox should be unchecked, and if they choose "no" it should remain checked. I'm new to Java ...

Adding a duplicated form causes the page to refresh unexpectedly

When the user clicks on the "#addOne" button, a clone of the previous form is displayed using jQuery. The data from these forms is relayed using Ajax to avoid refreshing the page when submitting. However, there seems to be an issue with dynamically created ...

Tips for using useState with dependencies on custom objects such as { filter[], sort[] }:

I am trying to use the useState Hook with a custom object that contains two arrays as shown below const [initConfig, setInitConfig] = useState<>({filter:[], sort:[]}); However, I am unsure of how to declare inside the angle brackets. The filter arr ...

Having trouble resolving 'datatables.net/js/jquery.dataTables.js' in a Vue and React Project using the Surveyjs quickstart template

Currently, I am juggling two distinct projects - one utilizing Vue.js and the other employing React. Both projects stem from quickstart templates offered by SurveyJS. Upon diligently following the setup guidelines and executing the npm run start command, I ...

Searching for a nested object in Javascript using regular expressions

Presenting my data structure: var foo = { "Category1": [ {"Company1": {"URL": ["DomainName1", "DomainName2"]}}, ... ], ... } Typically, I access DomainName1 like this: foo["Category1"][0][" ...

Obtaining the client's IP address using socket.io 2.0.3: a comprehensive guide

Currently, I am facing a challenge using socket.io v2.0.3 in my node.js server as I am unable to retrieve the client's IP address. Although there are several suggestions and techniques on platforms like stackoverflow, most of them are outdated and no ...

Unable to transfer the function's output to a variable

This is a code snippet relating to an object Obj.prototype.save = function (fn){ var aabb = Obj.reEditName(this.name, function(newName) { return newName; // Additionally attempted var foo = newName; return foo; ...

What techniques work well for managing permission tiers within the MEAN stack environment?

Following the insights from the book "MEAN Machine", I successfully implemented a basic token-based authentication system that restricts access to certain model data to authenticated users. Now, I am eager to enhance this system by introducing three disti ...