angular - ngModel shows previous value selected on md-select -
when console log selectedvendor in method vendorupdate shows previous value of selectedvendor instead of new value.
<div> <md-select id="vendorvariable" class="vm-select-wrap" (ngmodelchange)="vendorupdate()" [(ngmodel)]="selectedvendor" placeholder="aws" name="vendorvariable"> <md-option *ngfor="let vendor of vendors" value={{vendor.small}}> {{vendor.caps}} </md-option> </md-select> </div> ts file:
vendors: = [ {caps: "aws", small: "aws"}, {caps: "azure", small: "azure"} ]; selectedvendor :any; vendorupdate(){ this.selectedvendor = this.selectedvendor; console.log(this.selectedvendor); } on selecting value select dropdown selectvendor prints previous selected value, whereas current selected value should printed.
[(ngmodel)] equals: [ngmodel] , (ngmodelchange). suggest use either.
you can skip ngmodelchange if use two-way binding pankaj suggested. otherwise can use one-way binding , ngmodelchange. sidenote can use [value]="vendor.small" instead of value="{{vendor.small}}. [ ] bind variable.
<md-select [ngmodel]="selectedvendor" (ngmodelchange)="vendorupdate($event)"> <md-option *ngfor="let vendor of vendors" [value]="vendor.small"> {{vendor.caps}} </md-option> </md-select> ts:
vendorupdate(value) { this.selectedvendor = value; console.log(this.selectedvendor); }
Comments
Post a Comment