how to assign the value returned from function call to a variable inside html in angular 2

988 Views Asked by At
<select [(ngModel)]="country" (change)="stateList = getStateList(country)">
        <option *ngFor="let c of countryList" [value]="c.Country.CountryID"></option>
</select>

Here in (ngModelChange) I want to assign the value returned from getStateList() to a varible, but it just calls the function and the return value is not bound to the variable.

1

There are 1 best solutions below

6
On BEST ANSWER

You can simply assign inside the getStateList function itself

<select [(ngModel)]="country" (change)="getStateList(country)">
        <option *ngFor="let c of countryList" [value]="c.Country.CountryID"></option>
</select>

inside the component

getStateList(country : any){
   this.stateList = (getData);

}