Implementing multiple drop down menus in Angular 2/4

I am currently working on implementing two drop down menus in my Angular application. One is labeled shop list and the other is labeled godown list. The issue I am facing is that when I select a shop, the data updates correctly, but when I select a Godown, the data does not change. Both drop downs are present in the HTML code.

I suspect that the problem lies within my TypeScript file (Onselect) because even though I have implemented 2 drop downs in the HTML, I only have one function in my TypeScript file. As I am new to Angular development, any feedback on the drawbacks of this approach would be helpful:

 ngOnInit() { 
       // Code for populating Shop details
 }

 //Code for populating Godown details

onSelect(shopid: number, godownid: number) {       
    // Code for handling dropdown selections
}

// Separate method creation query

HTML code snippet:

 <span>
            <select class="formcontrol" name="outletDetail" (change)="onSelect($event.target.value)">
                <option value="0" disabled>Select a Shop</option>
                <option *ngFor="let outletDetail of outletDetails" value={{outletDetail.ShopID}}>{{outletDetail.ShopName}}</option>
            </select>
        </span>
        <span>
            <select class="formcontrol" name="godowndata" (change)="onSelect($event.target.value)">
                <option value="0" disabled>Select a Godown</option>
                <option *ngFor="let godowndata of GodownDetails" value={{godowndata.GodownId}}>{{godowndata.GodownName}}</option>
            </select>
        </span>

Answer №1

Try using the code [value]="outletDetail.ShopID" instead of value={{outletDetail.ShopID}}

component.ts

ngOnInit() {
    this.Service.FetchPopulateOutlets().subscribe(outletsData => {
        let allShops = {
            ShopName: 'All',
            ShopID: 0
        }
        this.outletDetails = [allShops, ...outletsData]
    }, error => {
        console.error(error);
        this.statusMessage = "Problem with the service.Please try again after sometime";
    });

    this._enqService.FetchGodownPopulateOutlets().subscribe(GodownsData => {
        let allGodowns = {
            GodownName: 'All',
            GodownId: 0
        }
        this.GodownDetails = [allGodowns, ...GodownsData]
    }, error => {
        console.error(error);
        this.statusMessage = "Problem with the service.Please try again after sometime";
    });
}

component.html

<span>
    <select class="formcontrol" name="outletDetail" (change)="onSelect($event.target.value)">
        <option value="0" disabled>Select a Shop</option>
        <option *ngFor="let outletDetail of outletDetails" [value]="outletDetail.ShopID">{{outletDetail.ShopName}}</option>
    </select>
</span>
<span>
    <select class="formcontrol" name="godowndata" (change)="onSelect($event.target.value)">
        <option value="0" disabled>Select a Godown</option>
        <option *ngFor="let godowndata of GodownDetails" [value]="godowndata.GodownId">{{godowndata.GodownName}}</option>
    </select>
</span>

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

AngularJS: display or conceal components using mouse interactions

Check out this example - http://plnkr.co/edit/iwvjJcUurUW2AvkDArfz?p=preview I want the delete button to only appear when hovering over the row and trigger a delete function (delete(name)) by passing the name parameter. Any suggestions on how I can make ...

Setting up TypeScript controllers for stateprovider configuration is made simple by following these steps

Suppose I have the following simplified controller: module App { "use strict"; export class StoreDetailController { constructor() { alert("Detail-Controller"); } } } The configuration for UI-Router looks like this ...

Unexpected Expression Error in React and WebStorm

Below is a snippet of code I am working with: 'use strict'; import {LocalizationTextType} from 'spio'; import * as React from 'react'; import * as ReactDom from 'react-dom'; import SimpleFlexBox from '../hel ...

Refreshing the webpage upon submitting with Angular2 and Firebase technology

Yesterday, I came across an Admin HTML template that I wanted to integrate with Firebase. However, when I tried to register and clicked on Sign in, the page would reload instead of carrying out the Firebase createUserWithEmailAndPass process. Here is a s ...

Property or method cannot be invoked on object

Currently I am exploring asp.net core alongside typescript and angular2. Upon running the project, an error appeared in the browser console: "Object doesn't support property or method 'call'". ...

Pyramid CORS does not support the PUT and DELETE HTTP methods

My current issue involves the pyramid framework. I have added a function to pyramid add_cors_headers_response_callback(event): def cors_headers(request, response): response.headers.update({ 'Access-Control-Allow-Origin': &ap ...

Converting data received from the server into a typescript type within an Angular Service

Received an array of Event type from the server. public int Id { get; set; } public string Name { get; set; } public DateTime Start { get; set; } public DateTime End { get; set; } For Angular and TypeScript, I need to transform it into the following clas ...

Chrome browser is not reachable due to a web driver error when running tests with the Protractor

Dealing with issues in Protractor end-to-end testing environments can be quite common. Despite searching extensively, I have yet to find a satisfactory solution for my specific problem. I am currently using the Protractor framework with the Jasmine test ru ...

Tips for sending web push notifications:

Currently, I have an Angular Progressive Web App (PWA) connected to a Laravel back-end serving as an admin panel. My goal is to implement web push notifications to the PWA whenever the admin creates a new News article on the back end. Since there is no use ...

observe the file currently residing on the server

Is there a way to display a server-based file within an HTML page using Angular 8.0.0? I attempted to use ngx-file-viewer, but encountered the error "Property 'wheelDelta' does not exist on type 'WheelEvent'". To address this issue, I ...

Comparing the Features of Angular 7 and Angular 8

Could someone explain the key distinctions between Angular 7 and Angular 8, especially focusing on the significant new addition of the IVY engine? I would appreciate details or a link to delve deeper into this concept for better understanding. ...

The method getDay is not recognized as a function in Typescript Angular

After searching for a solution, I came across a similar question that did not address the specific issue I am dealing with. The challenge I am facing involves parsing a date into a string. Below is my current implementation: export class DataFormater { ...

Lazy loaded Angular modules are causing interference despite having completely different paths

I am facing an issue with lazy loading different modules in my application. The problem arises when the /members path overrides the /groups path, causing the GroupListComponent to be replaced by the MemberListComponent when visiting /groups. It's puz ...

How to avoid truncating class names in Ionic 4 production build

I have been working on an ionic 4 app and everything was going smoothly until I encountered an issue with class names being shortened to single alphabet names when making a Prod build with optimization set to true. Here is an example of the shortened clas ...

In TypeScript, what is the return Type of sequelize.define()?

After hearing great things about TypeScript and its benefits of static typing, I decided to give it a try. I wanted to test it out by creating a simple web API with sequelize, but I'm struggling to understand the types returned from sequelize. Here ar ...

Testing the Express API with MongoDB on a local machine is successful but encounters a timeout issue on CircleCI

I am facing an issue with testing a RESTful API (built with Express in TypeScript) using Jest. The test passes successfully on my local Windows machine but times out on CircleCI. .circleci/config.ylm version: 2.1 jobs: build: docker: - image: ...

Whenever I attempt to launch my cross-platform application on an android device, an error occurs

I am currently in the process of developing a cross-platform application using NativeScript with Angular. While it runs smoothly on web, I encounter several errors when trying to run it on Android. Despite resolving many issues, there is one error that has ...

Can a MongoDb objectId be longer than 24 characters in length?

Seeking a solution to a problem that has eluded me in the documentation and on Stack Overflow: I am interested in encoding a unique identifying value for my documents within the object id. This would allow me to extract or compute the unique value when pa ...

Transforming JavaScript into TypeScript for Nuxt3

Currently, I am on Nuxt version 3.10.0 and using Vue3 in my project. The goal is to transition my JavaScript-based Nuxt3 project to TypeScript. Is it sufficient to just replace <script setup> with <script setup lang='ts'> in all .vue ...

Tips on leveraging an attribute for type guarding in a TypeScript class with generics

Is there a way to utilize a generic class to determine the type of a conditional type? Here is a basic example and link to TS playground. How can I access this.b and this.a without relying on as or any manual adjustments? type X<T> = T extends true ...