Looking to obtain a label, but unfortunately, no text is displayed on the screen

Dealing with Function Overcalls in AngularJS Expressions

I am trying to fetch and display the label associated with the selectedType value in the option tag. However, I am not seeing anything on the view, and multiple calls are being made in the console.

view.jsp

<select ng-if="RCDModel.id!=-1" class="form-control overloadDC"
        title="blablabla" disabled>
    <option value="{{RCDModel.selectedType}}"> 
      {{exprModelType(RCDModel.selectedType)}}
    </option>                                   
</select>

Controller.js

$scope.exprModelType = function(typeModel) {
    if (typeModel != undefined) {
        $scope.reunionType.forEach(function (type) {
            console.log("TYPE: "+type);
            if (type.id == typeModel) {
                console.log("TYPE ID: "+type.id);
                console.log("TYPE ID: "+typeModel);
                console.log("Libele: "+type.libelle);
                return type.libelle;
            }
        });
    }
    return "";
}

https://i.sstatic.net/Xb2Vw.png

Answer №1

It is important to note that the return statement within a forEach loop does not pass values back to the parent function.

Instead, consider utilizing array.find:

$scope.exprModelType = function(typeModel) {
    if (typeModel != undefined) {
        var idMatch = $scope.reunionType.find( _ => _.id == typeModel.id );
        console.log("TYPE: "+idMatch); 
        console.log("TYPE ID: "+idMatch.id);
        console.log("TYPE ID: "+idModel);
        console.log("Libele: "+idMatch.libelle);
        return idMatch ? idMatch.libelle : "";
    }
    return "";
}

For further details, refer to:

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

What is the best way to implement buttons dynamically in multiple divs created by Django using JavaScript loops?

I have been working on a Django project where I've created several HTML divs. My goal is to add a single button to each div. https://i.sstatic.net/DEIqL.png In the image provided, you can see a div with the class card-footer that I created using a Dj ...

Several radial progress charts in JavaScript

While attempting to recreate and update this chart, I successfully created a separate chart but encountered difficulties with achieving the second progress. The secondary chart <div id="radial-progress-vha"> <div class="circle-vha ...

Change HTML canvas data into Angular form data before sending it to the Laravel backend

My JavaScript code to convert a data URL to blob and send it as a form request is: var canv = document.getElementById("mainCanvas"); var dataURL = canv.toDataURL('image/jpg'); documentData = {"image": dataURLtoBlob(dataURL), "gameName": "empero ...

The scrolling behavior varies in Firefox when using the mouse wheel

Currently, I am working on a website where I want to display large text on the screen and have the ability to scroll two divs simultaneously. This functionality is already in place. I can scroll the divs, but I'm facing an issue with the jumps being t ...

I'm having trouble getting jquery css to function properly in my situation

I am trying to implement a fallback for the use of calc() in my CSS using jQuery CSS: width: calc(100% - 90px); However, when I tried running the code below, it seems like the second css() function is not executing. I suspect that there might be an issu ...

Only the test cases that passed were documented in Mochaweasome

Currently, I am utilizing the mochawesome report to document my cypress execution. The test case is displaying a simple pass without providing details about the steps taken or the assertions made in the report. Sample snapshot (Apologies for the excessive ...

Tips for updating values in a nested array within JSON

I am working with the following .json file and my goal is to update the values of "down" and "up" based on user input. "android": { "appium:autoAcceptAlerts": true, "appium:automationName": "UiAutomator2", ...

Updating the icon of a dynamically generated element in Javascript and Django depending on the query value or click event

After trying several methods, I finally found a way to change the icon on a button that was generated using a for loop on page load. Below is my element: {% for i in data %} <div class="accordion"> <div style="margin-le ...

What is the best way to organize and structure a node.js project for modularity?

In the process of developing a node.js project, I am adhering to the class constructor pattern as shown below: function my_class(x,y){ this.x = x; this.y = y; } The foundation of the project lies within the main.js file. It is imperative that any ...

What is the method for rotating a map using JavaScript?

My map built with Leaflet displays a route and a moving car marker. Now, I am looking to implement a feature where the map rotates based on the direction of the car. I have access to both the current coordinates of the car and the target coordinates. ...

Comparison Between Angular UI Router and ngRoute: A Brief Analysis

After creating a mini test focusing on UI Router vs. ngRoute, I found myself unsure about some of my answers. Could someone please take a look and help me confirm or correct my responses? The questions: UI Router can save state when tabs are switched, w ...

Looking for a dynamic submenu that remains active even after refreshing the page? Check out the jQuery

I encountered an issue with a menu I created using jQuery. When clicking on a submenu, the site refreshes and then the menu does not remain in the active state. I want it to stay active showing its menu and submenu when clicked. I have also created a fid ...

Utilizing JSON compression techniques on both the client and server ends for more efficient data transfer

I'm searching for a tool that can compress JSON on the server side (using C#) and then decompress it on the client side, as well as vice versa. The entire data model for my webpage is in JSON format and I need to find a way to reduce its size. I' ...

The controller in AngularJS seems to be elusive and cannot be located

I've run into an issue while using angular-mock to inject my controller for unit testing. The error message I keep receiving is as follows: [$injector:unpr] Unknown provider: PatientRecordsControllerProvider <- PatientRecordsController This is h ...

Switch out a section of the web address with the information from the button to

Before we begin: Check out this Fiddle My current goal is to create a functionality where clicking a button will replace the # in a given link with the text entered in a text box, and then redirect the user to that modified link. http://www.twitch.tv/#/ ...

Retrieving a specific value from a multi-layered array

Struggling with extracting numbers from a nested array in a JSON file and matching them with values in another array? Need to send the matched values to another function but can't seem to figure it out after two days of trying. Any advice or assistanc ...

Guide to displaying two messages in a single toast with react-toastify

Is there a way to have only one toast message display when the user clicks on the favorite button, showing either "Added to Fav" or "Removed From Fav"? I am currently able to display two separate toasts with different messages. ...

What is the best way to synchronize CouchDB with multiple PouchDB instances in an AngularJS application?

I need help with my Angular project. I'm trying to figure out how to sync multiple PouchDB databases to a single CouchDB instance without losing any data. Can anyone provide some guidance or advice? ...

Effortlessly sending information to the Material UI 'Table' element within a ReactJS application

I have integrated a materialUI built-in component to display data on my website. While the code closely resembles examples from the MaterialUI API site, I have customized it for my specific use case with five labeled columns. You can view my code below: h ...

Add the Google analytics JavaScript code to your ASP.NET web application

I am trying to integrate the Google Analytics code into my ASP.NET web page, but it is not tracking any data. I want to capture information such as geolocation, IP address, session ID, and browser details using Google Analytics. Below is the code snippet I ...