Here is a way to display the chosen option from a list using Angular Js

Seeking guidance on Angular.Js - I have a dropdown that successfully picks the selected data, but fails to display the selected value upon revisit. Is there a specific property I should set for this functionality?

Snippet of my code:

 <select class='form-control' id="CreateRouteType"
  ng-options="createRoute.Name for createRoute in   vm.CreateRouteList"
 ng-model="vm.ProcessDataSettings.CreateRouteTypeId" >
 <option value="vm.ProcessDataSettings.CreateRouteTypeId" selected></option>
                        </select>

Any suggestions on how to ensure the dropdown displays the selected value when revisiting the page?

Answer №1

Can you please verify if my understanding is correct? Do you want to know what happens to the value in memory when options are changed?

It seems you are using ng-model="vm.ProcessDataSettings.CreateRouteTypeId". Are you confident that the selected value is stored in vm.ProcessDataSettings.CreateRouteTypeId?

Answer №2

Consider this question: How can I preselect a dropdown value in AngularJS when retrieved from a webservice?

<select class='form-control' id="CreateRouteType"
ng-options="createRoute.Name for createRoute in   vm.CreateRouteList"
 ng-model="vm.ProcessDataSettings.CreateRouteTypeId">
                        </select>

Basically, in your controller's initialization function, you need to set the value of ng-model in the select tag to the desired preselected value. It should look something like this:

$scope.vm.ProcessDataSettings.CreateRouteTypeId = the object you want to preselect;

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

Assessing personalized directive attributes

I am currently working on a custom directive that will activate a specified event when a particular expression evaluates as true. The code below demonstrates how it can be achieved when binding a single value- <div ng-trigger="value.someBoolean" /> ...

React Material-UI: Trouble with Checkbox Toggle

I'm encountering an issue with my React code where the checkbox is not toggling when clicked. Here is the link to the codesandbox: https://codesandbox.io/s/inspiring-kirch-q6p4h The checkbox state initialization looks like this: const [checkbox, set ...

The file or directory node_modulesjquerydistjquery.min.js could not be found due to an error with code ENOENT

I am encountering an issue and need assistance: I've been following the instructions provided in this tutorial, but I'm continuously running into the following error: ENOENT: no such file or directory, open 'C:\Users\andrewkp ...

The update function now saves only the name property in the database, while the url property is stored as undefined

I utilized nodejs, mongoose, and angular to create a RestAPI with mean stack, focusing on updating provider records in my database. Below is the implementation of the put method: Object {_id: "553d27a24c47696420c6ee39", name: "nn", url: undefined, __v: 0, ...

Retrieving an item within another item

I'm attempting to retrieve the value of usertype within the result object, but I'm encountering issues with this. Here's what I've tried so far: if(data.result.usertype === 2){ console.log("redirect to type 2 user") } else if(data.re ...

Tips for accessing and manipulating the parent, sibling, next, and previous elements of the current element with AngularJS

Below is an example of HTML code where I have linked $scope properties and values to controls: https://i.sstatic.net/NRP0i.png This is the function that triggers when an image is clicked and changes the path of the images: $scope.ratingClick = function( ...

Error in parsing JSON: An unexpected token < was encountered at the beginning of the JSON input, causing a SyntaxError at position 0 when parsing with

I need to transfer an array from a PHP file to JavaScript and save it in a JavaScript array. Below is the snippet of JavaScript code: xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange=function(){ if (xmlhttp.readyState==4 ...

Is there a way to determine the size of an array following the use of innerHTML.split?

There is a string "Testing - My - Example" I need to separate it at the " - " delimiter. This code will help me achieve that: array = innerHTML.split(" - "); What is the best way to determine the size of the resulting array? ...

Tips for dynamically resetting the dataTable

When I create a datatable and add rows dynamically based on the selected option, I encounter an issue where I need to reinitialize the dataTable every time the option is changed. To address this, I have placed the reinitialization code inside the $("#selec ...

Node.js Middleware Design Pattern: Connectivity Approach

I am embarking on a journey to learn Javascript, Node.js, Connect, and Express as part of my exploration into modern web development stacks. With a background in low-level networking, diving into Node.js' net and http modules was a smooth process for ...

You must use the 'new' keyword to invoke the class constructor NextResponse | Implementing middleware in Next.js | Implementing role-based protection for routes in Next.js |

I've been working on implementing user role-based protected routes in my next.js project using middleware.js, but all of a sudden, I've encountered this issue. I'm not exactly sure why this is happening, so if anyone has a better approach to ...

The state initialization process is beginning with an [object Object] being passed into the setState function

Within the async function provided below, I am invoking stationData to verify that an array of objects is being passed into bartData (which currently consists of an empty array). Upon exploration, I have observed a response containing the anticipated array ...

Sometimes, React doesn't cooperate properly in the callback function of a setState operation

Imagine this scenario: callback = () => { ... } When is it appropriate to use this.setState({...}, this.callback); and when should I opt for this.setState({...}, () => { this.callback(); }); In order to maintain the validity of this within the ...

Finding and choosing a date from an ng-model datepicker using Selenium Webdriver - a guide

I am encountering an issue where I can open the date picker pop-up calendar with a click, but I cannot select a specific date from it. This is due to the input field being read-only, which means that any input provided through sendkeys or JavascriptExecuto ...

Is it possible for using str_replace('<') to protect against code injected by users?

Recently, I've been working on a script that involves user input. In this script, I use echo str_replace('<', '&lt;', str_replace('&','&amp;',$_POST['input']));. It seemed like a solid f ...

Transferring data from PHP to AJAX and then injecting it into an SQL query

I've been attempting to pass a datepicker variable into an onclick ajax function, which then sends it to another ajax method that passes the variable to an SQL query. The result of the query is then passed back into the ajax function to generate a cha ...

What is the best way to implement jQuery after new elements have been added to the DOM?

I'm currently working on a Sentence Generator project. The program is designed to take a list of words and retrieve sentences from sentence.yourdictionary.com based on those words. The first sentence fetched from the website is displayed using the cod ...

Angular TypeScript state management system

I am facing a challenge in connecting a controller to a state (using angular ui.router) where one way of writing it works, while the other does not. Successful example (with the controller registered under the module): this.$stateProvider .state(' ...

What is the reason that this particular JQuery code is malfunctioning in the IE browser once integrated into my website?

Currently, I am utilizing the DDCharts jQuery plugin from DDCharts JQuery to incorporate some charts into my website. After downloading the plugin and testing it in various browsers, I encountered an issue specifically with Internet Explorer 8+. Strangely, ...

I am looking to dynamically load a script only after retrieving specific data from a JSON file in Next.js

I am trying to ensure that the Script tag loads after the data.post.content is loaded within the HTML. Specifically, my goal is to execute the MathJax.js script inside the HTML. This is the code I have: return ( <div> <h1>{data.post ...