Is there a way to make a `select` in AngularJS refresh itself automatically?

I'm encountering an issue with the 'select' element. When I choose an option in the first 'select', the result does not immediately appear in the second 'select'. Instead, I have to manually refresh the page using 'F5' in order to see the results. add_parcelle.html

  <div class="row">
    <div class="col-md-12">
        <div class="form-group" ng-class="{'has-error':Form.type.$dirty && Form.type.$invalid, 'has-success':Form.type.$valid}">
            <label for="form-field-select-2">
                Type of parcel <span class="symbol required"></span>
            </label>
            <select name="type" ng-model="type" title="select" class="cs-select cs-skin-elastic" ng-change="sendType(Form.type.$modelValue)" required>
                <option value="" disabled selected>Select a type</option>
                <option value="Lot">Lot</option>
                <option value="Parcelle">Parcel</option>
                <option value="Zone">Zone</option>
                <option value="Plant">Plant</option>
            </select>
            <span class="error text-small block" ng-if="Form.type.$dirty && Form.type.$invalid">Field is required</span>
        </div>
    </div>
</div>

<div class="row">
    <div class="col-md-12">
        <div class="form-group" ng-class="{'has-error':Form.idParcelle.$dirty && Form.idParcelle.$invalid, 'has-success':Form.idParcelle.$valid && Form.idParcelle.$dirty}">
            <label for="form-field-select-2">
                Parent parcel <span class="symbol required"></span>
            </label>
            <select data-ng-init="showParents()" name="idParcelle" ng-model="idParcelle" title="select" class="cs-select cs-skin-elastic">
                <option value="" disabled selected>Select a parent</option>
                <option value="1">No parent</option>
                <option ng-repeat="p in parcelle" value="{{p.idParcelle}}"><div ng-if="p.parent.libelle">{{p.libelle}}</div></option>
            </select>
            <span class="error text-small block" ng-if="Form.idParcelle.$dirty && Form.idParcelle.$invalid">Field is required</span>
        </div>
    </div>
</div>

ParcelleController.js

$scope.sendType= function(type){

    $sessionStorage.typeParc=type;
    console.log($sessionStorage.typeParc);

};
$scope.showParents = function() {


    if($sessionStorage.typeParc=='Parcelle')
        $scope.showLots();
    else if($sessionStorage.typeParc=='Zone')
        $scope.showParcels();
        else if($sessionStorage.typeParc=='Plant')
            $scope.showZones();


};

In the first 'Select', I am using:

ng-change="sendType(Form.type.$modelValue)"

This allows me to store Form.type and use it in the function showParents(), which displays the result in the second 'Select'.

data-ng-init="showParents()"

However, this is causing my problem! Any help would be greatly appreciated. Thank you in advance :)

After editing by 'Gustavo Gabriel', this is the result: click here for image description

I can see the list in the 'select' when checking console but not on the page itself :p

Answer №1

To update the first select statement, make changes to your ng-change attribute as follows:

ng-change="sendType(Form.type.$modelValue); showParents();"

This modification should provide assistance =)

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

What is the best way to merge angularjs modules?

In my angularjs application using the codeigniter PHP framework, I have implemented 3 modules - cars.js for car details, cellphones.js for cellphone details, and home.js for home details. Each module caters to a different client's needs. I am trying ...

The issue with certain values not being filtered correctly in AngularJS

While working with AngularJS filters, everything seems to be running smoothly. However, I've encountered an issue where searching for a person with a salary of 30 (just an example) doesn't work unless I add another value. Can someone please expla ...

Access the child element of a span by targeting a specific attribute value using Protractor

Trying to check if a popover appears using protractor. Below is the snippet of HTML code with the popover in the last child span: <span tariff-popover="views/popovers/c2g/airport.html" class="ng-isolate-scope"> <span ng-transclude=""> ...

Encountered an error with rootscope:infdig when utilizing ng repeat loop

I have been working on this issue for a while now but I can't seem to find a solution. Within an ng-repeat loop, I am calling a function parseBug. This function is supposed to modify two fields and convert them into an array. However, I encountered a ...

Sending a file input to a Node.js server from an Angular service call

I have a basic multipart formdata that needs to be posted to a server running on node.js. <form action="/upload" enctype="multipart/form-data" method="post"> <span class="btn btn-file"> <input type="file" name="file" ng-model= ...

AngularJS directive: handling child elements

Is there a way to structure the directive below in order to have access to all the ul elements within the link function? In the code snippet provided, when examining the elm (logged in console), it appears as a comment type and ul are displayed as sibling ...

Time passed with altitude reference

I'm currently working on displaying the time elapsed in an angular.js application using angular-moment, moment, and moment-timezone. Everything is functioning correctly, but the displayed time is 6 hours ahead for individuals located in Spain due to t ...

Returning to the initial state after clicking on an element within a repeated set in AngularJS?

I'm currently facing a challenge, mainly due to my lack of understanding in basic AngularJs concepts. The issue arises when I interact with a list of clickable words. When I click on any of these words, their color changes individually thanks to the i ...

Is it recommended to use separate Controllers for each tab in Angular JS to load the pane?

Recently delving into the world of Angular JS and eagerly seeking expert advice and suggestions. Would it be advisable to use separate controllers for initializing each Tab to load the Pane content? Is assigning separate controllers a recommended approac ...

Creating a sequence of lights that alternate between on and off

I need to dynamically manage 5 on/off lights using Angular. These lights are connected in parallel to a working slider, sharing the same scope. The logic is simple - when the slider is at position 3, lights 1, 2, and 3 should be ON, while lights 4 and 5 sh ...

Sign in with Google / External authentication service

Currently working on an AngularJS application that includes Google login functionality. To implement this feature, I found a useful guide at the following link: . Additionally, there is a script that is called when the page loads: <script type="text/j ...

Having trouble with my AngularJS directive (possibly)?

Check out my main JavaScript file: var app = angular.module('app', [ 'ngRoute' ]); app.config(['$routeProvider', function($routeProvider) { $routeProvider .when("/calendar", { templateUrl: "views ...

AngularJS showcasing data in a visually appealing layout

Successfully connected API and displaying data, but now encountering an issue with formatting the data into a table. When using ng-repeat="item in items", if used within a tr tag, only one row is shown. If used within a tbody tag, it repeats the tbody. He ...

jQuery providing incorrect measurements for an element's height

I am encountering an issue with obtaining the height of the #header element in my AngularJS application. Despite using jQuery, the returned height seems to be incorrect. The current code snippet looks like this: $(document).ready(function() { function ...

Enable the ability to click on a row within the angular chart

I recently acquired the demo from However, I am wondering how I can set up a clickable row to direct users to another webpage. Any guidance on this would be greatly appreciated. ...

Unable to access complete map using ngmap and AngularJS

I am currently working with ngmap and encountered the issue shown in this screenshot https://i.stack.imgur.com/WchKT.png Here is my code: var app = angular.module('dv', ['ngMap']) app.controller('MC', function($scope){ ...

Is there a way to prevent users from selecting dates and times prior to today, as well as blocking out the hours of 9:00am

Users are required to select a date within the range of today's date and one month in the future, and a time between 9:00am and 9:00pm. How can I implement validation to ensure this? <div class="row"> <div class="col"> <label cl ...

AngularJS: Utilizing angular-filter for grouping by two columns

I may come across as a bit confusing, so please allow me to clarify. Note: An operational piece of code (POC) has been included with this post. I have an array of objects with 3 properties: name name team team_rank $scope.players = [ {name: & ...

Sharing data between controllers in AngularJSPassing information between controllers in AngularJS

My controller is responsible for fetching a list of airports, which is then used in a single input component for Departing and Arrival purposes. The autocomplete feature works well in both cases. I am trying to find a way to pass the selected airports from ...

What are alternative methods to exchange data between two controllers besides using services and rootscope?

In a recent interview, I was asked about sharing data between two controllers in Angular. I'm familiar with using services and root scope for this purpose. However, I'm curious if there's an alternative method to pass data between controller ...