Displaying a variety of values based on the specific URL

I am attempting to display specific values from an array of objects based on the current URL. For example, if the URL is "localhost/#/scores/javelin," I only want to display the javelin scores from my array.

Here is an example of what my array looks like:

$scope.ppl = 
            [
                {
                    firstname: 'Donald',
                    lastname: 'Trump',
                    from: 'USA',
                    run100m: ['1s','2s','3s'],
                    javelin: ['50m','20m','44m']
                },
                {
                    firstname: 'Foo',
                    lastname: 'Bar',
                    from: 'SWE',
                    run100m: ['1s','2s','3s'],
                    javelin: ['80m','10m','54m']
                },
            ];

There are over 15 types of sports and an unknown number of people in the array. I am struggling to find a solution that doesn't involve creating numerous arrays. I have tried various approaches but have not had success.

This is how my repeat function currently looks:

<tr ng-repeat="x in ppl">
        <td>{{x.firstname}}</td>
        <td>{{x.lastname}}</td>
        <td>{{x.from}}</td>
        <td><span ng-repeat="y in x.run100m track by $index">{{ y }}</span>
        </td>
        <td><button>edit</button></td>
    </tr>

Currently, this code only works with the "run100m" values. If the URL is changed to "/javelin," I want the javelin scores to be displayed inside the span tag.

The only solution I have found is to create:

<span ng-show=" URL == javelin"></span>

However, I am uncertain if this is the most efficient approach. My question is, how can I achieve this in a more efficient manner? The structure of "ppl" does not necessarily need to remain the same, but it would be ideal if all the information could be stored in a single variable.

Additionally, I want the repeat to be based on the variable:

var path = $routeParams.sport;

Answer №1

Utilize a property accessor within this code snippet:

<tr ng-repeat="person in people">
    <td>{{person.firstName}}</td>
    <td>{{person.lastName}}</td>
    <td>{{person.location}}</td>
    <td><span ng-repeat="event in person['eventType'] track by $index">{{ event }}</span>
    </td>
    <td><button>modify</button></td>
</tr>

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

MongoDB Driver Alert: MongoError - Cursor Not Found. Cursor ID 7820213409290816 was not located in the specified namespace db_name.collection_name

Having successfully created a Nodejs API server that connects to AWS MongoDB (version: 3.6), everything seems to function flawlessly when calling one specific API endpoint (api/lowest). However, upon making multiple simultaneous calls to this API (15 in to ...

Recovering antiquated submission script in JavaScript

Here is a form with input data: <form id = 'myform'> ... <td><input type="checkbox" name="supplier_aid" value="on" checked disabled >{$output.t_artikelnr}</td> <td><input type="checkbox" n ...

Unable to access the following element using jQuery's next() method

Can someone help me understand how the "next" function works in jQuery? I'm trying to reveal a hidden textarea when a span element is clicked. The hidden textarea is supposed to be the immediate next sibling of the span, but it's not working as e ...

Using CSS to style the footer with a body height set to 100%

I am currently working on an angularJS web app with a basic template structure: <html> <head> <link rel="stylesheet" href="style.css" /> </head> <body id="top"> <!-- Templates with vi ...

Sorting an object array by date is causing a problem

UPDATE: Finally cracked the code on this issue. I initially assumed that Date was interpreting the date ("29-04-2020") as DD-MM-YYYY, when it should actually be MM-DD-YYYY. For instance, here's an object array I'm working with: let t ...

Header for AngularJS blog post worldwide

Is it possible to create a universal header in AngularJS that functions similarly to jQuery? For example, something like the code below: $.ajaxSetup({ beforeSend: function (xhr) { xhr.setRequestHeader('Requested-With', 'XMLHttp ...

Is the new mui LoadingButton not available in the latest version?

According to the material UI documentation found at here, you are supposed to import LoadingButton from '@material-ui/lab/LoadingButton'; However, I am unable to locate this folder within mui/lab and the import statement is resulting in an erro ...

Issue encountered with AngularJS .run not executing

It seems like the module is not functioning properly. In my index.js file, I have the following code: // index.js ---type 1 // .run not working... var myServiceToRun = require('./myservice.js'); var mod = angular.module('myApp',[]); mo ...

AngularJS 2 customClass tab with conditional styling

Is it possible to conditionally set a custom class for an Angular 2 Bootstrap tab? I've tried setting it with a static value but would like to do so based on a condition. If you want to learn more about tabs in Angular 2 Bootstrap, check out: Here&a ...

Converting an array of ByteArray into a MemoryStream

There is a method in my code that returns an array of ByteArray: public byte[][] GenerateImage(ImageFormat format, ImageSize size); I want to store this array into a MemoryStream: var imageArray = instanceName.GenerateImage(ImageFormat.Jpeg, ImageSize.D ...

The FileReader encountered an error because the first parameter is not a 'Blob' type

I seem to be encountering an issue with a javascript FileReader that is throwing the error Uncaught TypeError: Failed to execute 'readAsDataURL' on 'FileReader': parameter 1 is not of type 'Blob'. This problem occurs intermitt ...

Is there a way to determine if a submit button has been clicked in order to prevent my function from executing?

I'm currently developing a platform for uploading images. Once a user uploads an image successfully, it gets saved in 4 different sizes within separate folders. They are then redirected to the same page with new content, where they can proceed to crop ...

A guide on deleting a specific value from a JSON array in PHP

Here is a code snippet that I am working with: $json_encode = '{"OS":"Android","Title":"Galaxy"}'; $json_decode = json_decode($json_encode); foreach($json_decode as $key => $value) { if($key == 'Title') { unset($key); ...

How can I make the outer function in AJAX's onreadystatechange function return 'true'?

Within my Javascript/AJAX function below, I am striving for a return of true or false: function submitValidate() { var xmlhttp; xmlhttp = null; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari try { xmlhttp ...

Having identical functions with varying IDs and the same variable in Ajax is causing issues

Here, I have two HTML rows with different IDs. When the function ItemSearch() is called, I want to display the search results for both IDs. I am new to JavaScript and AJAX. ***1st Html*** <div class="justlauchSearch"> <div class="input-gro ...

The JavaScript function document.getElementById.onclick is not functioning as expected

One issue I am facing involves counting all downloads on my website. My current approach is to increment a value in my database each time a download button is clicked, and then display this value. Despite trying multiple methods, the download count always ...

Enhance user experience with Google Optimize by conducting A/B testing on

I am seeking advice on Google Optimize CSS code. My goal is to perform A/B testing on button colors throughout my entire WordPress website at www.interica.si. When I make changes to the CSS code in the edit mode, it seems to affect all buttons, but when I ...

The webpage continues to refresh after executing a JavaScript function triggered by the AJAX response

I have experimented with various solutions for calling a JavaScript function returned from an AJAX response. While each method worked to some extent, I found that using an alert within the refreshResults function was necessary in order to display the resul ...

Is there a way to inject C++ text into an input field on a webpage using QWebEngine?

I want to integrate a website with QWebEngine to manipulate input commands using Qt's event filters and more. The specific website I am working with requires a username/email and password, and I aim to manage the input of this text on my end. This inv ...

Encountering an issue with the UNION operator in Typescript causes an error

Currently, I am utilizing the OR operator within Typescript to designate that a product could be of type ProductI OR CartResponseInterface.Product This is how it is structured: product: ProductI | CartResponseInterface.Product However, when attempting t ...