Angular js is failing to populate dropdown values

I'm encountering an issue with editing a user object. When clicking the edit button, some values in the form are loading correctly, but three values are not populating even though I'm receiving the data from the service.

HTML

    <div class="col-xs-4 col-sm-4 col-md-3 col-lg-3 label-right">
        <label class="control-label">{{::'label.country'|translate}}</label>
        <label class="asterisk">*</label>
    </div>
    <div class="col-xs-8 col-sm-8 col-md-9 col-lg-9 controls">
        <select id="selectCountry" name="selectCountry" required ui-select2="select2CountrySettings" ng-model="selectedUser.country">
            <option ng-repeat="country in countryList" value="{{country.name}}" ng-selected="{{country.name == selectedUser.country}}">{{country.name}}</option>
        </select>
        <span class="help-block" ng-show="editUserForm.selectCountry.$dirty && editUserForm.selectCountry.$error.required">{{::'error.required'|translate}}</span>
    </div>
</div>

<!-- Locale -->
<div class="row control-group" ng-class="{error:editUserForm.selectLocale.$dirty && !editUserForm.selectLocale.$valid, success:editUserForm.selectLocale.$valid}">

    <div class="col-xs-4 col-sm-4 col-md-3 col-lg-3 label-right">
        <label class="control-label">{{::'label.user.locale'|translate}}</label>
        <label class="asterisk">*</label>
    </div>
    <div class="col-xs-7 col-sm-7 col-md-9 col-lg-9 controls">
        <select id="selectLocale" name="selectLocale" required class="locale-select" ui-select2="select2LocaleSettings" ng-model="selectedUser.culture">
            <option ng-repeat="locale in localeList" value="{{locale.name}}" ng-selected="{{locale.name == selectedUser.culture}}">{{locale.name}}</option>
        </select>
        <span class="help-block" ng-show="editUserForm.selectLocale.$dirty && editUserForm.selectLocale.$error.required">{{::'error.required'|translate}}</span>
    </div>
</div>

Javascript

function reloadUser() {
    loadingDataBegin();

    userDetails.getUserById(userDetails.getSelectedUser().id).then(function (response) {
        $scope.selectedUser = response.results;
    }, function (error) {
        if (error.status !== undefined && (error.status === 401 || error.status === 403)) {
            $rootScope.authentication.reAuthenticate();
        } else {
            toasty.generalError();
        }
    });
}

While $scope.selectedUser is fetching all values from the service, the last three dropdowns for Locale, Country, and Organization are not being populated correctly (image).

Answer №1

  1. Implement ng-options to facilitate selection in dropdown menus

Instructions on usage

ng-options="item.id as item.name for item in names"
  1. Employ ng-if to link the selected value with the appropriate model

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

Utilize AngularJS to interact with JSON data

Greetings, I trust you are doing well. I have successfully created an API using PHP to fetch data from SQL and convert it into JSON. However, I am facing a challenge in manipulating the PHP code to retrieve the JSON data as per my requirements. I believe ...

Utilizing Jasmine with AngularJS: A Guide to Mocking the window.user.username

As a newcomer to using Jasmine, I am currently grappling with the task of mocking the window.user.username object while testing an AngularJS application. Let's say we have a variable called applicationUser that stores the value of window.user.usernam ...

What is the process for importing a JavaScript export file created from the webpack.config file?

Issue at Hand In the process of testing APIs, I encountered a dilemma in setting up either the DEV or Production environment. This involved configuring API endpoints for local testing and preparing them for production use. To achieve this, I utilized NOD ...

Is it possible to use a variable from a popup window's JavaScript to call a jQuery function in the parent window?

Is there a way to use JavaScript in a popup window to call a function from the parent window that contains jQuery? Are there any straightforward examples available for reference? ...

What is causing me to not receive a 404 error when dealing with an unhandled state?

Currently, I am utilizing $stateProvider to configure my states in the following manner: constructor($stateProvider, $urlRouterProvider, $locationProvider) { $stateProvider. state("something", { url: "/index.html" }) ...

Is it possible to replace a server-side templating engine with Angular 2's server-side pre-rendering?

As a novice in web development, I have recently been exploring angular 1.x, react.js, and angular 2 (eventually deciding on angular 2). Lately, I've been intrigued by the concept of server-side pre-rendering. In my understanding, this process is ...

Spin the text inside an <li> element generated by JavaScript

I am currently working on a unique script designed to create a custom number of slices for a circle. The items in the circle are being displayed as shown in this generated circle image. This is the Javascript code I have been using: for () { men ...

executing a controller method in AngularJS

Looking to trigger a controller function from a directive tag. Check out this demo: https://jsfiddle.net/6qqfv61k/ When the 'Export to Excel' button is clicked, I need to call the dataToExport() function from appCtrl since the data is ready for ...

Fetching various data from MongoDB using NodeJS and presenting it in Jade(Pug) template

I am working with MongoDB collections and need to showcase them on my website, creating a dynamic page that updates automatically. Specifically, I am dealing with team members' information in the database. Here is an example of how my collections loo ...

Pressing the ENTER key does not submit the text box data in Rails/Bootstrap, but clicking the SUBMIT button does

I need assistance with my Rails 4 and Bootstrap 3 project. I have implemented an email address field on my page (localhost:3000) where users can enter their email and click the SUBMIT button to send it to the MongoDB database. However, pressing the ENTER k ...

How to send a function from a parent component to a child component in Vue.js

I'm trying to figure out how to pass the parent component's method to the child component. Here's the scenario: when I click the confirm button on my modal (child component), it needs to send the data from the parent form (parent component). ...

Displaying time text in input element due to browser bug

I am faced with a perplexing puzzle that has left me scratching my head. Here are two seemingly identical pieces of javascript code, but one behaves unexpectedly (take note of the Console.Log): Updates the UI once, then abruptly stops updating: http://js ...

Alert the host about any updates

I am currently working on an ASP.NET application that is hosted by a C# application using WebBrowser. The ASP.NET application runs within the C# application environment. My challenge lies in finding a way to notify the C# application when certain events, ...

What is the best way to trigger the jQuery-File-Upload event within this function?

Before uploading a file, I want to check the API first. $('.file_upload_button_wrapper').on('click', function () { // perform check here $.ajax({ url: '/?app=files&getfile=ajax%2Fupload.php', ...

What is the best way to fetch all the orders from my product schema using response.send?

This is my custom Product schema const productSchema = new mongoose.Schema({ title: { type: String, required: [true, "Title is required"] }, details: { type: String, required: [true, "Details are r ...

"Can someone help me figure out how to retrieve a smaller array? I can't seem to get

I need help reducing an array. My desired output should be [1,5,4], but unfortunately I am getting back an empty array. let arr=[1,[2,3],4] let newarr=[] let myarr=()=>{ for(i=0;i<3;i++){ array=arr[i].reduce newarr.push(arra ...

The React callback is failing to update before navigating to the next page

I'm facing an issue that seems like it can be resolved through the use of async/await, but I am unsure of where to implement it. In my application, there are three components involved. One component acts as a timer and receives a callback from its pa ...

Issue: ReactJS + MaterialUI + TypeScript - Property 'component' does not exist?Possible error in ReactJS: component property is

Currently, I am designing my own custom typography. However, I have encountered an error while implementing it. I have been referring to the following documentation: https://mui.com/material-ui/api/typography/ Here is the code snippet that I am using: h ...

What should be transmitted to the front-end following the successful validation of a token on the server?

My process starts with a login page and then moves to the profile page. When it comes to handling the token on the backend, I use the following code: app.use(verifyToken); function verifyToken(req, res, next) { if (req.path === '/auth/google&ap ...

Exploring the world of unit testing in Angular, particularly focusing on the templateUrl of directives. This includes integrating

Currently, I am facing an issue with karma unit testing in my angular app. The problem arises when I try to load the template in my directive using templateUrl instead of embedding it directly. This approach is necessary for scalability as the app grows bi ...