Preventing the need for reassessing ng-options

I have been utilizing ng-options to create a dropdown menu for values that may change infrequently. In a larger example, I have approximately 50 options in the array, and I noticed a decrease in performance each time I made a selection. It seems that ng-options is being reevaluated every time I make a change. Is there a way to prevent this from happening? You can view a simplified example here:

http://jsfiddle.net/BBra9/2/

Specifically, this function:

scope.formatItem = function (item) {
    console.log('formatting item.');
    return item.someProp1 + '/' + item.someProp2;
};

is called to format each item for display in the dropdown, but I only want it to run once per item on the initial list.

The Chrome console displays a total of 9 log statements before any selection is made, followed by 3 after each subsequent change. My initial thought is to use compile, but I would appreciate some guidance.

Answer №1

Have you considered running it at the start and storing the values in a separate property?

for (let j=0;j< array.length ;j++){
   array[j].property = formatData(array[j]);
}

DEMO

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

The API key fails to function properly when imported from the .env file, but performs successfully when entered directly

Working with Vite has been quite an experience for my project. I encountered a situation where using my API key directly worked fine, but when trying to import it from .env file, I faced the error message in the console below: {status_code: 7, status_me ...

Looking for an image that spans the entire height of the container

I need help with positioning an img inside a div container that has a background color. I want the image to overlay on top of the div, extending beyond its height without causing any scroll bars. Here is a fiddle related to this issue: http://jsfiddle.net ...

Is it secure to send the one-time authorization code for Google+ Hybrid server-side flow over HTTP?

Hello, I have decided to transition from using Google's Client-side flow to the Hybrid server-side flow. Previously, I would send the client an access_token and then transfer it to the server to verify the user before logging them in or creating a new ...

Transform the array into a series of values separated by pipes

How can I transform an array like this - ["lat","long","abc","def","abcc","deef",] into [lat,long | abc,def | abcc,deef] using javascript? I am currently encountering an issue with the distance matrix API... Here is the code snippet I have: export asyn ...

Tips for properly invoking an asynchronous function on every rerender of a component in Vue.js

Situation: An analysis module on a website that needs to display three different data tables, one at a time. Approach: The module is a component containing three buttons. Each button sets a variable which determines which table to render. Depending on the ...

I'm having difficulty mocking a function within the Jest NodeJS module

I have a module in NodeJS where I utilize a function called existsObject to validate the existence of a file in Google Storage. While testing my application with Jest 29.1.2, I am attempting to create a Mock to prevent the actual execution of this functio ...

When working with Vue 3, remember that inject() function is only allowed within setup or functional components

I'm puzzled as to why I keep encountering this error. I am attempting to utilize the Vuex store in a composition function, but for some reason, it keeps throwing an error regarding inject (even though I'm not using inject at all). My application ...

Chrome extension: some APIs disappear after chrome.runtime.reload() is called

Issue with my Chrome Extension involving the chrome.tabs API. Extension runs smoothly, but encounters a problem after chrome.runtime.reload(); occasionally, the chrome.tabs reference becomes undefined upon restart. This renders the extension unusable and ...

Adjust Ajax JSON query parameter

Here is the code I am currently working with: http://jsfiddle.net/spadez/nHgMX/2/ $(function() { function log( message ) { $( "<div>" ).text( message ).prependTo( "#log" ); $( "#log" ).scrollTop( 0 ); } $( "#city" ).autoco ...

Unable to load JavaScript within ASP.NET framework

I'm looking to experiment with a basic JavaScript function within an ASP.NET environment. Movies/Index.cshtml <!-- Including my custom local JavaScript file --> <script src="~/Scripts/JavaScript.js" type="text/javascript"></script> ...

Tips for updating parent data with multiple values from a child component

Check out the code snippet below. I seem to be stuck on a crucial component. Despite going through the documentation and watching tutorials on Vue2, I can't seem to grasp this key element. Any assistance would be greatly appreciated. If my approach i ...

Problem with Postman's form-data functionality

I am facing an issue with using Postman and body->form-data. The code works perfectly fine when I use express.json parser with body->raw and body->urlencoded, but for some reason it does not work with formData. https://i.sstatic.net/6DuCd.png ht ...

Display an error message if the input field is empty, then conceal the message once the input field is filled

Can anyone assist with a Vue.js app issue I'm facing? Currently, when the search input is empty, an error message appears - which is okay. However, I want to hide this error message as soon as the user starts typing in the search field. The code for m ...

Unable to reset input in a functional component using React JS

I have a component named TextInput that is responsible for rendering an input element: function TextInput({ type = "text", label, name, required = false }) { const [value, setValue] = useState(""); function handleChange(e) { se ...

Using a Python list as an argument in a JavaScript function

How can I pass a python list as an argument to a JS function? Every time I attempt it, I encounter the error message "unterminated string literal". I'm baffled as to what's causing this issue. Here is my python code (.py file): request.filter+= ...

Validating forms using ajax, php, and mysql for seamless user input processing

I'm currently in the process of creating a login form that includes an instant email address verification feature against my database. Despite my efforts and attempts to make this functionality work, I have faced challenges in getting it to function ...

When I assign my welcome channel ID to MongoDB, I notice that the last two digits always seem to change

Why does the last two digits of my channel ID change to "00" when I try to set my welcome channel ID to MongoDB? For example: 954226649841430572 --> (when sent to database) 954226649841430500 https://i.sstatic.net/blLIL.png Here's my code: await ...

Navigating the grid layout in Material UI can be tricky to

I'm struggling to grasp the concept of the grid system in material UI. Within my grid container, I have two grid items that I want to be centered and occupy the entire width. The button element appears centered, but the typography element does not. A ...

Having difficulty retrieving items from Mongoose-Node database

I am currently working with a Mongodb database that stores resume objects. These objects contain various skills information and I have set up a node-express server to query the database based on specific skills. For example, when querying for a skill like ...

Issues encountered when attempting to parse a JSON object using jQuery

My PHP file is set up like this: <?php include('connection.inc.php'); ?> <?php header("Content-type: application/json"); ?> <?php $sth = mysql_query("select * from ios_appointments a join ios_worker w join ios_partners p wher ...