I am able to fill in the ServiceType field, but I am struggling to find the correct options for the ServiceName dropdown menu

Is there a way to dynamically update the ServiceName dropdown options based on the selected value in the ServiceType dropdown?

$scope.ServiceTypeAndName = [    
    { 
      "id":0,
      "type":"",
      "list":""
    },
     { 
      "id":1,
      "type":"In-Person",
      "list":["ADL Functional Assessment", "Community Functional Assessment", "Future Care Cost Analysis"]
    },
     { 
      "id":2,
      "type":"Paper Review",
      "list":["OT - In Home Assessment - ABI", "OT - In Home Assessment Attendant Care with Form 1", "OT - Occupational Therapy Assessment"]
          
    },
     { 
      "id":3,
      "type":"Administration",
      "list":["Situational Assessment", "Situational Assessment (OT) - Day 1", "Situational Assessment (OT) - Day 2", "Construction Cost Consulting"]
    }  
];


$scope.selectedLine = [{"Event_ID": "100", "Service_Type": "In-Person", "Service_Name": "Community Functional Assessment"}, {"Event_ID": "101", "Service_Type": "Paper Review", "Service_Name": "OT - Occupational Therapy Assessment"},{"Event_ID": "102", "Service_Type": "In-Person", "Service_Name": "Future Care Cost Analysis"}];
<select ng-model="selectedLine.Service_Type" name="ServiceType" class="form-control">
   <option ng-repeat="temp in ServiceTypeAndName" value="{{temp.type}}">{{temp.type}}</option>
</select>

<select ng-model="selectedLine.Service_Name" name="ServiceName" ng-required="selectedLine.Service_Type!=''" class="form-control"> 
   
</select>

For instance, if the first object is loaded, the "In-Person" option should be pre-selected in the first dropdown and the "Community Functional Assessment" value should be pre-selected in the second dropdown. Any changes in the first dropdown should update the options in the second dropdown accordingly.

Answer №1

Your data may not be perfectly organized, but it's definitely manageable:

View Working Plunker Example

To navigate through the ServiceTypeAndName array effectively, you'll need to use a filter like this:

$scope.selectedLineChanged = function () {                  
   $scope.SelectedServiceTypeAndName = $filter('filter')($scope.ServiceTypeAndName, $scope.selectedLine.Service_Type)[0];           
};  

If you're wondering how to load selected items into the selectedLines array, take a look at how it's done in the select box of the Plunker example.

By changing the top box, you can automatically match the remaining two boxes.

https://i.sstatic.net/rWo74.png

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 deliver hefty files to users? Utilize the node-telegram-bot-api

bot.sendDocument(id, 'test.zip'); I am facing an issue while trying to send a 1.5GB file using the code above. Instead of being delivered to the user, I receive the following error message: (Unhandled rejection Error: ETELEGRAM: 413 Request En ...

Unleashing the power of React: Integrating raw HTML <a href> tags with JavaScript

I am currently working on a small web app that mimics browsing WikiPedia by fetching raw HTML content of WikiPedia articles through its API. I then display this HTML in my app using "dangerouslySetInnerHTML". I am faced with the challenge of enabling a us ...

Can you explain how to add a string array to an HTML div using AJAX?

My output consists of a string array that comes from PHP JSON. I am trying to display this output in an HTML div tabcontent, but I'm unsure of how to achieve this. Below is a snippet of my code - can anyone help me with this? [{"id":"1","p_name ...

What is the process of implementing FFT in node.js?

Struggling with implementing FFT in node.js is proving to be quite challenging for me at the moment. Despite experimenting with three different libraries, I find them all poorly documented, which only adds to the complexity of the task. My current setup i ...

To achieve the desired format, where should I press or manipulate the information?

I need help with manipulating arrays to generate a specific JSON file structure. I've made some progress but got stuck at this point: var T_nn_IN = document.getElementById('datatablenewname'); var tabledata_newname_initialname = []; ...

Showing events from MySQL database on Vue.js Fullcalendar

I am trying to fetch events from my MySQL database and pass them to my Vue component to be displayed on the FullCalendar. However, the event array is being populated with a full HTML document. Below is my EventController: public function getEvents() { ...

Google Maps API is successfully loading from an HTML file, however, it is not functioning properly when accessed

I am facing an issue while trying to connect to the Google Maps API through an AngularJS application on my localhost. Despite finding the javascript file in the HTML and displaying 'test1' in the console, the `initMap` function is not being calle ...

Encountering an error when attempting to save an ajax JSON response to a variable and receiving an

I am attempting to make an ajax call and store the JSON response in a variable. My goal is to display the JSON response in two separate Jqgrids, with one displaying half of the response and the other displaying the remaining half. I need some ideas on how ...

Is Iterating Over Elements Using Angular4/Typescript's ForEach Possible?

While searching for information, I noticed many responses regarding the use of ngFor. However, my question pertains to the angular.forEach() method utilized in my Angular 1 controllers. Unfortunately, these are being identified as errors in TS and fail to ...

The toggle-input component I implemented in React is not providing the desired level of accessibility

Having an accessibility issue with a toggle input while using VoiceOver on a Mac. The problem is that when I turn the toggle off, VoiceOver says it's on, and vice versa. How can I fix this so that VoiceOver accurately states whether the toggle is on o ...

Incorporating External Content into Your HTML Website

Looking to incorporate third-party content in the form of an HTML page within my own website, I considered utilizing iframes. This would allow me to embed the external HTML page within my site while keeping their libraries and CSS separate from mine. Howe ...

Creating a CSS grid layout with a scrollbar positioned on the left side and content filling from left to right

How can I move the scrollbar to the left while keeping ng-repeat population from left to right? I'm using an ng-repeat to fill a grid that is 3 by X (Width by height). By default, the scroll bar appears on the right side. I want to position it on the ...

Facing an error with Angular.js

In my current project, I am faced with the task of uploading weather data from an .xls file to an SQL database. This is my first experience working with AngularJS, so I followed a tutorial and everything appeared to be running smoothly. Here is my code: ...

Bidirectional binding of input with angular's uib-popover-template

Lately, I have been working on uib-popover and encountered a puzzling issue. My goal is to create a popover with a template that includes an input field with an initial value. However, I've noticed that updating the content in real-time based on the ...

Updating the error state of a TextField Component in React MaterialUI upon clicking a button

After clicking a 'search' button, I want to validate input fields in my input form. Many solutions suggest validating the input live as it is entered, but I prefer not to do this because some of the validation processes are costly operations, su ...

Upon initial launch of the application, JavaScript fails to load

I am currently working on developing a hybrid app that utilizes iOS as the native platform and Cordova-Phonegap for HTML support. Upon launching the application for the first time, we encounter an issue where the JavaScript fails to load. Although we are ...

Guide on utilizing map function in JavaScript and Vue to generate a fresh array

I am working on implementing a map method in JavaScript and Vue to generate a new array of objects while only including specific items in each object. I have designed a user interface with 2 checkboxes corresponding to 2 distinct objects: <div v-for ...

Should I use Mongoose schema methods or prototype functions?

I am curious about the functionality of functions and ES6 classes in relation to new objects created from a mongoose schema. I wonder if the functions are duplicated for each new object and what the best approach is when utilizing ES6 classes. To illustrat ...

Issue with saving cookie from Express.js backend to Nuxt.js frontend

After successfully creating an authorization server using Express.js, I encountered a problem when trying to save the access and rotating refresh tokens as signed cookies. The issue arose from having separate backend and frontend servers with different dom ...

Phantom Browser Triggered Karma Unit Test Error

I used jhipster to create my project and incorporated a theme purchased from themeforest. However, I encountered an error when attempting to create a war file. It seems like the theme's components are throwing errors when tested with karma. PhantomJS ...