Hiding and showing dropdown list options in AngularJS using ng-hide and ng-show

I'm currently developing a web application that includes four dropdown lists.

<select>// loading dynamic data</select
<select>// loading dynamic data based on selection from dropdown1</select
<select>// loading dynamic data based on selection from dropdown2</select
<select>// loading dynamic data based on selection from dropdown3</select

My goal is to make dropdowns 2, 3, and 4 uneditable. When the user changes the selection in dropdown1, dropdown2 should become editable. Then, when the text in dropdown2 is changed, dropdown3 should become visible, and so forth.

I would greatly appreciate your assistance with this. Thank you!

Answer №1

To implement the functionality you need, utilize ng-disabled and enable it on the ng-change event trigger. I will demonstrate this using 2 dropdowns, but you can scale it up to accommodate more options if necessary.

<select ng-change="fruitselect(fruitname)" ng-model="fruitname" ng-init="fruitname = fruits[0]">
  <option ng-repeat="fruit in fruits" value="{{fruit}}">{{fruit}}</option>
</select>

<select ng-model="desertname" ng-disabled="isDessertDisabled">
  <option ng-repeat="dessert in desserts" value="{{dessert}}">{{dessert}}</option>
</select>

In the second dropdown, take note of the ng-disabled="isDessertDisabled". In your Angular controller:

$scope.fruits = ['apple', 'orange','banana', 'grapes', 'plum'];
$scope.isDessertDisabled = true;
$scope.desserts = ['apple pie', 'orange crush', 'red wine', 'plum cake']
$scope.fruitselect = function(fruitname){
  // perform an HTTP call to retrieve desserts based on selected fruit
  // $scope.desserts = response from $http call
  $scope.isDessertDisabled = false;
} 

Although I have manually inputted the dessert array here, in your scenario, it will be populated dynamically via an HTTP call. Subsequently, isDessertDisabled will be toggled to false, thereby enabling the second dropdown with the fetched dessert options.

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

Issue encountered with updating canvas texture twice in A-Frame and pdf.js while operating in virtual reality mode

Using the power of A-Frame and pdf.js, I embarked on a quest to build an incredible VR application for viewing PDF files. Everything seemed to be working seamlessly on my desktop - flipping through PDF pages, rendering them onto a canvas, it was a sight to ...

What is the best way to showcase the information stored in Firestore documents on HTML elements?

Currently in the process of designing a website to extract data from my firestore collection and exhibit each document alongside its corresponding fields. Below is the code snippet: <html> <!DOCTYPE html> <html lang="en"> <head> ...

When working with AngularJS, you can enhance your application by implementing a global AJAX error handler if one has

Is there a way to set a global AJAX handler that will only be called if an error handler is not already defined for a specific AJAX call? Some of my AJAX calls need to execute certain logic if an error occurs (such as re-enabling a button), while others s ...

Save and retrieve documents within an electron application

Currently, I am developing an application that will need to download image files (jpg/png) from the web via API during its initial run. These files will then be stored locally so that users can access them without requiring an internet connection in the fu ...

Utilize Jquery to dynamically replace HTML partials based on the device's screen resolution

Currently working on a project using Bootstrap 3, the client has requested significant changes to the structure for mobile views. In previous projects, I have utilized Zurb Foundations Interchange: - and found it to be fantastic! I am curious if there a ...

I'm having trouble getting Grunt Source Maps to function properly within the foundation-press theme

I'm struggling to enable source maps for the npm package grunt-sass. Here's a snippet from my Gruntfile.js: The issue lies in this line: sourceMap: true, at line 13 module.exports = function(grunt) { var jsApp = [ 'js/app.js' ...

Struggling to make JavaScript read JSON data from an HTML file

I am currently working on developing a word search game using django. One of the tasks I need to accomplish is checking whether the entered word exists in a dictionary. To achieve this, I have been converting a python dictionary into JSON format with json. ...

Linking two block backgrounds with CSS or JavaScript: A comprehensive guide

I'm working on a website that has a challenging background image. I want to add text at a specific point in the background, but I'm having trouble figuring out how to do it. The page is split into two sections, with each section supposed to disp ...

Learn the process of inserting JSON data into a MySQL database with Node.js

var express = require('express'); var app=express(); var length; var affiliate = require('flipkart-affiliate'); var url = require('url'); var moment=require('moment'); var mysql = require('mysql'); var body ...

Reset form after submission in Angular 1.5

I've gone through all the recommended posts related to this issue, but I'm still struggling to clear the form fields after submission. Despite trying to use $scope with $setPristine in my controller as syntax, the form fields remain uncleared. F ...

Ensure that the array of JSON objects is a subset of another array of JSON objects

I am looking to compare each array in testEdge with newarr and find the matching id for each array in testEdge const testEdge = [ [{ id: '0', from: '0', to: '1' }, { id: '1', from: '1&ap ...

How should NodeJS be utilized for accessing various directories?

I'm currently working on a basic web application and I'm having trouble accessing different JavaScript files stored in a separate folder from the main one. To provide a clearer picture, here is my current file structure: myapp ├── clientSi ...

Save user input data into an Excel file using PHPExcel

Could someone assist me with storing values from my form inputs to Excel using PHPExcel? I have successfully stored data from my table to Excel, but now I want to store the values from my inputs. Can anyone help me, please? Example of the form inputs: ent ...

When should you utilize child or nested states in AngularJS UI-Router?

I'm currently working on a large AngularJS application that follows the design of having one .html file per state. Each view is represented by a single HTML file, and I am avoiding including multiple HTML files per page. $stateProvider.state('fi ...

The discord.js TypeScript is throwing an error stating that the 'index.ts' file is missing when trying to run 'ts-node index.ts'

I have been working on creating a discord bot using discord.js and TypeScript. However, when I attempt to start the bot by running 'ts-node index.ts', I encounter the following error: Error: Cannot find module 'node:events' Require stac ...

Error: Unexpected token 'undefined' encountered, which is not recognized as a primary expression. This error occurs at column null within the expression [xx], beginning at [xx%]

When using my sorting function, it does not work properly if the column name contains a %. For instance, when columnName == "calldrop", my function works as expected. However, when columnName == "calldrop%", I encounter an error message that says: Syntax ...

Animated smooth updates in d3 line graphs are the key to creating dynamic and

I'm attempting to modify an example of Animated Line Graphs from: http://bl.ocks.org/benjchristensen/1148374 <div id="graph1" class="aGraph" style="width:600px; height:60px;"></div> <script> function draw(id, width, height, upd ...

Guide on using PHP to remove the trash icon glyphicon

I am currently creating a data table that includes various actions, one of which is the option to delete a row from both the table and the database. My challenge lies in figuring out how to successfully delete a particular row by simply clicking on the Tr ...

What is the best way to style the current element being targeted in React?

In my React application, I am trying to dynamically adjust the height of a textarea element based on its content. I want to achieve this by utilizing an 'onchange' listener to trigger a resize function. While I have successfully implemented the ...

Why am I unable to access the array once the loop has finished?

While utilizing the Google Maps API and AngularJS (1.5.8), I encountered an issue where I couldn't access markers that were created in a loop. The code snippet below is located inside the initMap function: var markers = []; for(var i=0; i<10; i++ ...