AngularJS ng-repeat - cascading dropdown not refreshing

I'm dealing with an AngularJS issue where I'm trying to create a cascade dropdown like the one below:

            <div class="col-sm-2 pr10">
            <select class="PropertyType" ng-controller="LOV" ng-init="InitLov(140)" ng-model="PropertyType" ng-change="update(PropertyType)" >
                <option value="" selected="selected" disabled="disabled"> {{type ? type: 'Property Type'}} </option>
                <!-- <option value="">-- Select Type --</option>-->
                <option ng-repeat="Lov in LovList" value="{{Lov.Value}}" >{{Lov['Lable'+Lang]}} </option>
            </select>
        </div>
        <div class="col-sm-2 pr10">
            <select class="PropertySubType" ng-controller="LOV" ng-model="PropertySubType" >
                <option value="" selected="selected" disabled="disabled" >{{subType ? subType: 'Property Sub Type'}}</option>
                <!--  <option value="">-- Select Sub Type --</option> -->
                <option ng-repeat="Sub in SubType" value="{{Sub.Value}}" >{{Sub['Lable'+Lang]}} </option>
            </select>
        </div>

Now, in the Angular file:

            $scope.update = function (id) {
            $http.post("API/WebsiteService.asmx/getSubPropertyLov", { type: id }).success(function (data) {

                debugger;
                var rr = eval('(' + data.d + ')');
                $scope.SubType = rr.result; 

            });
        }

The API successfully returns data and the SubType scope captures it. However, there seems to be an issue with updating the dropdown data for PropertySubType. *Note that this function is within the LOV controller.

Answer №1

Avoid duplicating ng-controller="LOV" on each select element, as this will create separate scopes. Instead, place both selects within the scope of the same controller.

Additionally, replace ngRepeat with ngOptions:

<div ng-controller="LOV">
  <div class="col-sm-2 pr10">
    <select class="PropertyType" 
      ng-init="InitLov(140)" 
      ng-model="PropertyType" 
      ng-change="update(PropertyType)"
      ng-options="Lov.Value as Lov['Lable' + Lang] for Lov in LovList">
      <option value="" selected="selected" disabled="disabled"> {{type || 'Property Type'}} </option>
    </select>
  </div>
  <div class="col-sm-2 pr10">
    <select class="PropertySubType" 
      ng-options="Sub.Value as Sub['Lable' + Lang] for Sub in SubType"
      ng-model="PropertySubType">
      <option value="" selected="selected" disabled="disabled">{{subType || 'Property Sub Type'}}</option>
    </select>
  </div>
</div>

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

ag-grid Server Side pagination function to enable independent setting of last row

Currently, I am utilizing ag-grid, Angular 7, and implementing a server-side datasource with pagination. In my API setup, I initiate two requests: the first request provides the total number of items in the table, while the second fetches the data for the ...

What is the process for configuring CORS in Wamp?

Currently, I have set up Wamp as my local server to test my Angular application. In my development process, I am utilizing $resource to fetch data from an API on my server. However, I keep encountering the following error message: XMLHttpRequest cann ...

Styling CSS for disabled nested elements

In a project I am currently working on, I've noticed that disabled items do not appear disabled enough. My initial plan was to easily address this issue with some CSS. Typically, adjusting the opacity is my go-to solution to achieve the desired effec ...

Issues with navigating jQuery UI links while offline in Google abound

Hello, I am a newcomer to jQuery and I am facing an issue with my code. I added the <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> but for some reason, my jQuery is not working. I have tried searching ...

Retrieve information from the accuweather api endpoint

I am struggling to retrieve JSON data from the AccuWeather API using a locationKey in PHP. The error message I am receiving is: file_get_contents(https://dataservice.accuweather.com/forecasts/v1/daily/1day/55488?apikey=0NSY9T1tFGo0NIXOYp23lro8DsuOcwPJ): fa ...

Troubleshooting jQuery Div Separation Problem

Currently, I am working on implementing resizable sidebars using jQuery and potentially jQueryUI. However, I am encountering an issue with the resizing functionality. Specifically, the right sidebar is causing some trouble in terms of proper resizing, wher ...

Ways to address issues in my tree-building algorithm when the parent ID is missing

Currently, I'm in the process of creating a function to build a tree. Everything seems to be functioning correctly until I encounter a scenario where a document is added with a parentID that doesn't exist in the list. The root node is intended to ...

Ways to identify when a modal window is being closed in the angular-ui $modal component

I am currently utilizing the $modal from angular-ui to generate a modal window. Below is the code snippet for creating the modal: this.show = function (customModalDefaults, customModalOptions, extraScopeVar) { //Create temporary objects to work with s ...

Utilizing titanium to develop a functionality that listens for button presses on any area of the screen

I am trying to simplify the action listener for 9 buttons on a screen. Currently, I have individual event handlers set up for each button, which seems inefficient. Is there a way to create an array of buttons and manipulate them collectively? For example ...

A step-by-step guide on retrieving a value from a DateTime picker in a React application

I am utilizing Material-UI to create a DateTime picker. You can check out my demo code here. In order to observe the current selected value, I have added console.log to the function handleChange. However, I am facing an issue where the value does not chan ...

Downloading a file through a JavaScript link in HTMLUnit: A step-by-step guide

Looking to download a file with HTMLUnit from a javascript link is proving to be quite challenging. The journey begins at this page. When clicking on the "Authenticate with Java Web Start (new method)" link, a .jnlp file is downloaded, initiating a Java pr ...

JOLT Guideline for transforming field value into field identifier

I need help converting a JSON payload so that the field name becomes the value of the field. The existing jolt file works when field values are different, but it creates an array in the response if the field values are the same. Please can someone provid ...

When implementing `useRouter().push()` in Next.js, it has the ability to refresh

I have recently started using a custom node server in my Next.js app. Previously, useRouter().push() was working fine without a custom server and providing a seamless single-page app experience. However, with the custom server, it now refreshes my applicat ...

Having trouble retrieving POST parameters

I'm attempting to send a post parameter (key: test, value: somevlaue) using PostMan with the restify framework. I've tried two methods, but both are failing: The first method results in this error: { "code": "InternalError", "message": "Can ...

What is causing the lack of updated data on the components when navigating to a different page? (Vue.JS 2)

I am working with 2 components The first component looks like this : http://pastebin.com/M8Q3au0B Due to the long code, I have used pastebin for it The first component calls the second component The second component is as follows: <template> ...

Setting up and safeguarding your Stripe Secret API Key in an Ionic Project

I have a burning question that seems to evade me: What is the best way to conceal my confidential Stripe API key within an ionic project? ...

Make a quick call to the next function within the error handling module for a

Currently, I am facing an issue while trying to call the next function within the error handler of my node + express js application. In each controller, I have a middleware known as render which is invoked by calling next, and I wish to achieve the same f ...

Troubden array filtration in Angular is malfunctioning

I recently developed an angular "filter component" intended to filter an array and display its contents. The keyword used to filter the array, value, is obtained from another component through a service. While the HTML displays both the value and the entir ...

Is it necessary for me to use bindActionCreators?

While going through a post, I couldn't help but notice that the bindActionCreators method from redux wasn't being utilized. Is there a specific reason for this? Could it be that the method is not necessary in this context? The post in question ...

When trying to append in jQuery, the error "JQuery V[g].exec is not a

Attempting to create a script that adds a table to a div within the website using the following function: function generateTable(container, data) { var table = $("<table/>"); $.each(data, function (rowIndex, r) { var row = $("<tr/>"); ...