The View is not reflecting changes in the Variable

Is there a way to disable all the buttons when selectedplace is null in the Dialog, as it currently works when the Dialog first starts but remains activated all the time when the option is changed?

I have attempted the following:

Customized HTML:

      <label for="place">Einheit</label>
      <div class="input-group mb-3">
        <div class="input-group-prepend">
          <button class="btn btn-outline-secondary" [disabled]="!selectedplace" type="button">Change</button>
        </div>
        <select id="place" name="place" #place="ngModel" required class="form-control" [(ngModel)]="selectedplace" (change)="onDropdownChangeplace()">
          <option value=""></option>
          <option *ngFor="let i of UI_places" [ngValue]="i">{{i.name}}</option>
        </select>
        <div class="alert alert-danger" *ngIf="place.touched && !place.valid">Bitte eine Eingeben eingeben!</div>
        <div class="input-group-append">
          <button class="btn btn-outline-secondary" [disabled]="!selectedplace" type="button">Add</button>
          <button class="btn btn-outline-secondary" [disabled]="!selectedplace" type="button">Delete(red)</button>
        </div>
      </div>

TypeScript(declared):

public selectedplace: Place;

Any suggestions on what action I should take next?

Answer №1

What method are you implementing in onDropdownChangeplace? It seems like you are dynamically assigning a value based on the index that has been changed.

If no value is assigned (in the case of an empty selection), the ngModel will retain the previous value.

You can view the working example on stackblitz here, where based on your code, the enable and disable functionality is working properly.

The code in the component is provided below, with the HTML left unchanged according to your specifications.

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: [ './app.component.css' ]
})
export class AppComponent {
    public UI_places = [{id:0, name: 'home'},{id:1, name: 'work'}];
    public selectedplace: Place;

    onDropdownChangeplace() {
        // Your implementation goes here
    }
}

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 are the recommended techniques for utilizing prototypal and prototype-based inheritance in modern JavaScript (ES6) and TypeScript?

Some older discussions on Javascript prototypal inheritance & delegation can be found below: Benefits of prototypal inheritance over classical? classical inheritance vs prototypal inheritance in javascript I am curious about the current (2018) recom ...

There is no index signature that includes a parameter of type 'string' in the specified type

I have a background in mobile app development and am looking to learn more about TypeScript. How can I declare a map object with the form [string:any]? The error is occurring at line: map[key] = value; Element implicitly has an 'any' type becaus ...

Round off Kendo Column Chart edges and add a personalized highlight shade

https://i.sstatic.net/RpHnR.png Is there a way to create a kendo column chart with rounded borders similar to the image provided? Below is the code snippet I am currently using. Additionally, how can I customize the hover-over color for the columns in the ...

Using JavaScript to define an array of objects

My issue lies with transforming a JSON structure like the one below: [{ "groupid": 29, "percentage": 14 }, { "groupid": 29, "percentage": 22 }, { "groupid": 59, "percentage": 66, }] I am looking to convert it into the format shown ...

Learning how to serve static files in a virtual directory with Angular Universal and Asp Net Core

I am currently working on an Angular Universal + Asp Net Core App. One of my tasks involves serving a static file from a "virtual directory". In the ASP NET Core code, I have implemented the following: app.UseFileServer(new FileServerOptions { ...

using props as arguments for graphql mutation in react applications

Here is the structure of my code: interface MutationProps{ username: any, Mutation: any } const UseCustomMutation: React.FC<MutationProps> = (props: MutationProps) => { const [myFunction, {data, error}] = useMutation(props.Mutati ...

Having trouble with ESLint in VSCode? The ESLint extension seems to be ignoring linting rules after starting a new project within VSCode

I recently started using the ESLint extension in my VSCode editor for my React project. After creating the starter files, I ran the following command in my terminal: eslint --init This allowed me to choose the AirBnb style guide with React, which generat ...

What is the most effective method for declaring callbacks on objects in Typescript?

I am currently working on a sidebar menu component that is connected to a service holding items in the menu. This allows multiple sources to make alterations to the menu as needed. Each item in the menu currently follows the SidebarItem interface: export ...

Using React Native with TypeScript to Select the Parent and Child Checkboxes within a FlatList

My objective is to ensure that when a user selects a checkbox for one of the parent items ('Non Veg Biryanis', 'Pizzas', 'Drinks', 'Desserts') in the flatlist, all corresponding child items should also be selected au ...

Limiting the combinations of types in TypeScript

I have a dilemma: type TypeLetter = "TypeA" | "TypeB" type TypeNumber = "Type1" | "Type2" I am trying to restrict the combinations of values from these types. Only "TypeA" and "Type1" can be paired together, and only "TypeB" and "Type2" can be paired tog ...

What is the best way to prevent routing to <a href="#" > in Angular 8?

When I try to use a local reference in Angular, it looks something like this: <a class="btn-floating btn-large blue" href="#">button</a> However, instead of directing me where I expect, Angular is redirecting me to another link: localhost:420 ...

In TypeScript, the nested object structure ensures that each property is unique and does not repeat within

Here is the current state of my interface. I am wondering if there is a way to streamline it to avoid repeating properties in both parts. export interface Navigation { name: string; roles: Array<number>; sublinks: NavigationItem[]; } ...

Error in Firebase Emulator: The refFromUrl() function requires a complete and valid URL to run properly

Could it be that refFromURL() is not functioning properly when used locally? function deleteImage(imageUrl: string) { let urlRef = firebase.storage().refFromURL(imageUrl) return urlRef.delete().catch((error) => console.error(error)) } Upon ...

What is the process for displaying an enum in an Angular Mat Form Field?

Hey there! Check out my awesome app - My app. I need help with writing a Java/Visual Studio script for my app. How can I make it so that when I click on "Upgrade" for the id 1, the "Account" row displays CASH as the default value? Right now, no value is sh ...

Material Design Autocomplete search feature in Angular 2

I'm encountering some challenges with autocomplete in Angular2 Material Design. Here are the issues I'm facing: 1. When I type a character that matches what I'm searching for, it doesn't display in the autocomplete dropdown as shown in ...

The argument with type 'void' cannot be assigned to a parameter with type 'Action'

Just getting started with Typescript and using VSCode. Encountering the following Error: *[ts] Argument of type 'void' is not assignable to parameter of type 'Action'. (parameter) action: void Here is the code snippet causing the err ...

Writing TypeScript, Vue, and playing around with experimental decorators

After creating a Vue project through Vue-CLI v3.0.0-beta.15, the project runs smoothly when using npm run serve. However, TypeScript displays an error message stating that support for decorators is experimental and subject to change in a future release, bu ...

Updating Angular 8 Component and invoking ngOninit

Within my main component, I have 2 nested components. Each of these components contain forms with input fields and span elements. Users can edit the form by clicking on an edit button, or cancel the editing process using a cancel button. However, I need to ...

Utilizing functions from external modules in Angular

Recently, I created an es6 module with some exported functions and published it on npm after uploading its transpiled es5 code. Right now, I am in the process of trying to integrate this package into an Angular project that utilizes SystemJS as a module l ...

Navigating an array of JSON objects with the http client and Observables in Angular: A Step-by-Step Guide

Here is the URL I want to make an HTTP request from a service in Angular: The data consists of an Object containing an array of Features. The Features array includes 4 Objects - type, properties, geometry, and id. I aim to store the properties and geomet ...