What could possibly be causing my ng-model and ng-selected to be disregarded by my select

Having an issue with a select box that is not selecting the option bound to ng-model or ng-select. Instead, it initially selects the hard coded value but then overrides my selection with the last item in the list. Even after stripping it down to its bare minimum, I am unable to find a solution.

This is the HTML page:

<!doctype html>
<html lang="en>

    <head></head>

    <body>
        <div ng-app="myapp">
            <div ng-controller="myController">
                <select ng-model="freezeCalendar_model" ng-options="freezeCalender.calendarID as freezeCalender.name for freezeCalender in freezeCalendarList"></select>
            </div>
        </div>
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular.min.js></script>
        <script src="script.js></script>
    </body>

</html>

This is the script.js file:

var app = angular.module("myapp", ["controllers"]);

var controllers = angular.module("controllers", []);
controllers.controller('myController', function ($scope) {

    $scope.freezeCalendar_model = 162;

    $scope.freezeCalendarList = [{
        "id": 104,
        "name": "ABC"
    }, {
        "id": 202,
        "name": "123"
    }, {
        "id": 121,
        "name": "xyz"
    }, {
        "id": 224,
        "name": "hello"
    }, {
        "id": 162,
        "name": "bam"
    }, {
        "id": 164,
        "name": "boom"
    }];

});

I've also created a plnkr here. This particular issue is puzzling me as I have other selects working perfectly fine and cannot figure out what's wrong with this one.

Any help or advice would be greatly appreciated.

Answer №1

It seems like there is an issue with how you are referencing the id. Once I corrected that, everything worked perfectly for me.

Original:

freezeCalender.calendarID as freezeCalender.name

Corrected to:

freezeCalender.id as freezeCalender.name

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

How can I modify my code to ensure that trs and th elements are not selected if their display property is set to none?

I am currently working on creating a filter for my pivot table, but I am unsure of how to dynamically calculate the sum of each row/column based on whether they are displayed or not. If you need any other part of my code, feel free to ask. To hide employee ...

getStaticProps function in Next.js fails to execute

My [slug].js file includes two Next.js helper functions, getStaticPaths and getStaticProps. These functions are exported and create the path posts/[slug]. I have also added a post file named hello.json. However, when I try to access localhost:3000/posts/he ...

What causes CSS to fail to load in React but work normally in Next.js?

We are currently experiencing an issue with a component located in a Git Submodule that is being used by both Next.js and React. While everything is functioning correctly in Next.js, React is unable to accept the way the CSS is being loaded: import styles ...

Can you explain the significance of the order of elements in the Three.js BufferGeometry vertex positions array?

This array showcases the vertex positions sourced from this particular section of the three.js official documentation: var vertexPositions = [ [-1.0, -1.0, 1.0], [1.0, -1.0, 1.0], [1.0, 1.0, 1.0],     [1.0, 1.0, 1.0],     [-1.0, 1.0, 1.0] ...

Can you create a stroke that is consistently the same width as the container BoxElement?

Utilizing a BoxElement provided by the blessed library, I am showcasing chat history. New sentences are inserted using pushLine. To enhance readability, days are separated by lines (which are added using pushLine). The width of each line matches that of t ...

Reactjs - There was an error: $node.attr(...).tooltip is not defined

I am currently troubleshooting the SummerNote mention library and encountering an issue - Uncaught TypeError: $node.attr(...).tooltip is not a function The versions I am using are: - "react-summernote": "^2.0.0", - React version: "react": "^16.8.6", ...

In React Js, the state is being updated correctly when console logging, however, the user interface is not reflecting

Recently, I encountered an issue with updating the UI after clearing the input states in my object. Despite setting the input values to empty strings upon clicking the clear all button, the UI does not reflect these changes as expected. The initial state ...

Sorting through an array of objects based on a key and value that match another object

Is it possible to filter or query an array with the following structure? [ { 'xml:id': 'Name1', sex: { '$t': 'M' }, occupation: { n: 1 ...

calling object functions using additional parentheses

After reviewing the passport.js documentation, I came across this piece of code: app.get('/login', function(req, res, next) { passport.authenticate('local', function(err, user, info) { if (err) { return next(err); } if (!u ...

ng-model establishes a connection with objects, not properties

Having just started my journey with AngularJS and JavaScript, I decided to create a simple app that allows users to input their name and age, and then displays the list of users and their ages. Here is the code I put together: var main = angular.module( ...

When attempting to make my styles responsive, I found that they broke due to duplicate classes on the landing page I was creating with next.js and styled components

Something strange is unfolding, and I find myself confused about the overall situation. Let me try to explain it the best I can. On my landing page, there are three different components: const Home = () => { return ( <> <Head> ...

What is the method for selecting a specific row in a Primefaces Datatable using HtmlUnitDriver and Selenium?

Check out this code snippet: import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import org.openqa.selenium.htmlunit.HtmlUnitDriver; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriv ...

AngularJS: Transferring data from ng-repeat to a bar chart

Utilizing the countBy function from angular-filter to group and tally the number of entries for a specific column. I'm looking to transfer these values into a separate bar chart on the same page. Despite attempting various methods, I haven't been ...

"The issue persists with multiple JavaScript forms failing to work as expected when preventDefault

Within a jQuery document ready function, I've included the following code: jQuery("#frmUpdateDet").submit(function (e) { jQuery.ajax({ type: 'POST', url: './php/updateCred.php', data: jQ ...

Encountered an import error when using "npm run build", but it runs successfully with "npm start"

My React app is running smoothly with npm start, but I encounter an error when trying to build it using npm run build. The error message I receive is: `Creating an optimized production build... Failed to compile. Attempted import error: './parseq-lan ...

Automated form with built-in calculations

Whenever a product is selected from the dropdown menu, the price value should be automatically filled in the input field with ID #price. Then, the user can enter the quantity in the input field with ID #quantity, and the total sum of price multiplied by qu ...

Can terminating a POST XHR request be trusted?

Running an apache server with PHP 5.4. I've set up a form that sends an asynchronous request to the server and stops any previous requests if the button is clicked again before the current request is completed. If I repeatedly click the button quick ...

Tips for setting up cookie-based authentication in a SvelteKit and MongoDB environment

I am looking to integrate cookie authentication into my SvelteKit & MongoDB application. Specifically, I want to understand how to effectively utilize hooks, endpoints, set up a database connection, and showcase this functionality within a template proje ...

Interactive planetary visualization using three.js in real-time

As I work on my react project, I'm developing a globe and looking to initialize it accurately with respect to a specific time, whether it be the current time or a future time. The goal is for this globe to correctly align itself with the day and night ...

The issue arises when Node.js fails to identify the input fields that were dynamically inserted into the form

I came across a question similar to mine, but I found it challenging to apply the solution to node js. In my project, users can add items to a cart by clicking on them, which are then dynamically added to a form using jquery. However, upon submission, only ...