The option list in AngularJS is cleared when an option is selected

In my current project, I am developing a django-tastypie api application with angularjs as the JavaScript framework. The main part of this application involves managing curriculum objects, each containing a list of grade objects and each grade object further containing a list of subjects. Here is an example of my data structure:

{'id':1,
'name':'cbse',
'grades':[{'id':10,
            'name':'matriculation',
            'subjects':[
                        {'id':1,'name':'science'},
                        {'id':2,'name':'Math'},
                        {'id':3,'name':'English'}
                       ]
        }

I have structured my data in such a way that each object carries its related objects. My goal is to display these objects in select boxes so that selecting one object dynamically loads the related objects in other select fields. For example, choosing a curriculum from the dropdown should populate the grades select options with the corresponding data. However, I encountered an issue where the curriculum select box becomes empty after selection.

Here is a snippet of my HTML code:

<label>Select Curriculum</label>
    <select ng-model="qt_curriculumlist" ng-options=" curriculum.name for curriculum in qt_curriculumlist" ng-change="loadGrades()">
</select></br>
<label>Select Grade</label> 
<select ng-model="qt_gradeslist" ng-options="grade.name for grade in qt_gradelist " ng-change="loadSubjects()">
</select>
<label>Select Subject</label>
<select ng-model="qt_syllabuslist" ng-options="subject.name for subject in qt_subject_list" ng-change="loadTopics()">
</select>

Initially, the curriculum options load correctly in the select field, but upon selecting an option, the list becomes empty.

Answer №1

The reason for the error is that you've assigned your ng-model with the same name as your list.

To resolve this, assign a unique variable to the 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

Unable to produce scrolling animation using JavaScript

I'm trying to implement a feature on my website where the page scrolls with a sliding effect when the user presses the "Scroll" button. However, I've encountered issues as it doesn't seem to work despite adding the necessary tags to my HTML ...

Managing several items within one function

I am working with a json file that contains similar data sets but different objects. { "AP": [{ "name": "Autogen Program" }, { "status": "Completed" }, { "start": "2014-05-05" }, { ...

Steps to open specifically the WhatsApp application upon clicking a hyperlink, image, or button

I need a code for my HTML website that will open the WhatsApp application when a user clicks on a link, image, or button while viewing the site on a mobile device. Only the WhatsApp application should be opened when a user interacts with a link on my webs ...

angularjs determining the appropriate time to utilize a directive

I have been delving into JavaScript and AngularJS for approximately a month now, but I still find myself unsure of when to use directives. For example: I am looking to display appointments in a table with the date as the table header. I envision having bu ...

What is preventing the MenuItem component from functioning as a Link in React Material-UI?

Hey there! I've been trying to implement a popover menu that changes the URL and component after clicking on an item, but unfortunately it's not working as expected. I created a setup in this sandbox: https://codesandbox.io/s/romantic-surf-40p19? ...

Dim the brightness of an image on Internet Explorer

I discovered this code on another site and it functions flawlessly in Chrome and FF, however, IE (version 11.0.9) doesn't seem to like it. -webkit-filter: grayscale(0%); -moz-filter: grayscale(0%); -o-filter: grayscale(0%); filter: grayscale(0%); fil ...

What techniques are most effective for creating unit tests in a Node.js environment?

One of the challenges I am facing is writing a unit test for a module where I load a mustache template file. To tackle this, I am exploring the use of mocha, chai, and rewire. Below is an excerpt from my module.js: var winston = require('winston&apo ...

Incorporating local JSON data into HTML: A Step-by-Step

I'm completely new to javascript and the utilization of json. What I want to accomplish is quite straightforward, although I am encountering difficulties. My objective is to create a website consisting of two pages: one that showcases artists and ano ...

Images obscure dropdown menu

The issue I am experiencing with my blog is that the dropdown menu is appearing behind the image slider on the main page. You can see it here: Can anyone offer guidance on how to prevent this from happening so that the dropdown menu is not obscured? Just ...

Using an element with the href property in conjunction with react-router: a comprehensive guide

My goal is to implement the navigation.push(url) functionality upon clicking an anchor tag element in order to prevent the app from refreshing when navigating to a new page, thus allowing me to maintain the application state. The decision to use this on a ...

Tips for controlling a "collapsed" state for every intricately nested node within a tree

My data structure is complex and dynamic, illustrated here: const tree = [ { name: "Root Node", collapsed: true, nodes: [ { name: "Node 1", collapsed: true, nodes: [ { name: "Sub node" ...

Can you provide guidance on utilizing the Login Event within the Electron Framework?

I need some assistance in understanding the functionality of the Event: 'login' feature within the Electron Framework. Is this similar to the Password Autofill/Remember Password feature typically found in web browsers? I'm interested in util ...

Tips on transforming a JSON array object into a JSON array

**Background:** I have been utilizing lodash to eliminate the empty key from my JSON data. However, upon removal of the keys, it transforms my array into an object. For instance: { "projection": "Miller", "series": [ { "mapPolygons": { ...

How to troubleshoot window.location not functioning in PHP, JavaScript, and

There is a software that utilizes Ajax Get. However, the code provided below seems to be malfunctioning. What steps can I take to rectify this issue? Javascript snippet: <script> function purchase_item(itemID) { $.ajax({ ...

What is the easiest way to connect to MongoDB and add a new post with just a few lines of code?

Currently, I'm working with express.js and node.js. Can you share a brief snippet of code for connecting to mongo and inserting a post into the database? ...

Is there a way to detect when a user has recently updated their Chrome Extension in order to send them notifications?

I have implemented an info button in my extension, where a red dot appears on the top right corner to alert users of new updates whenever they update the extension. Currently, I achieve this by storing a row in localStorage when users view the updates. If ...

Data is not found in req.body when making a fetch request

I have been attempting to send a fetch request to my server, but I am consistently receiving an empty req.body. Here is the client-side script: const form = document.getElementById('form1') form.addEventListener('submit', (e) => ...

A step-by-step guide on utilizing links for downloading PDF files in Vue/Nuxt

Having some trouble opening a PDF tab in my Vue application with NUXT and Vuetify... any suggestions? I attempted to use: <a href="../static/docs/filename.pdf" target="_blank">Download PDF</a> I also tried using <nuxt-link> but it didn ...

What are the distinctions in how jQuery behaves when an element is assigned to a variable versus in Javascript?

I've noticed that when I assign a jQuery element to a variable, it doesn't match the element in a comparison. However, if I assign a JavaScript element, it does... test1 = $(".the_div"); console.log(test1 == $(".the_div")); // This logs false ...

Can angularjs html, css, and js files be intercepted?

Is it possible to create an http interceptor that can intercept not only requests made using the $http service, but also css, html, and js files used in templates? Shown below is the code for the existing interceptor: app.factory('redirectIntercepto ...