如何将函数调用返回的值分配给 html in angular 2 中的变量
how to assign the value returned from function call to a variable inside html in angular 2
<select [(ngModel)]="country" (change)="stateList = getStateList(country)">
<option *ngFor="let c of countryList" [value]="c.Country.CountryID"></option>
</select>
在 (ngModelChange) 中,我想将值 returned 从 getStateList() 分配给一个变量,但它只是调用函数并且 return 值未绑定到变量.
您可以简单地在 getStateList 函数内部赋值
<select [(ngModel)]="country" (change)="getStateList(country)">
<option *ngFor="let c of countryList" [value]="c.Country.CountryID"></option>
</select>
组件内部
getStateList(country : any){
this.stateList = (getData);
}
<select [(ngModel)]="country" (change)="stateList = getStateList(country)">
<option *ngFor="let c of countryList" [value]="c.Country.CountryID"></option>
</select>
在 (ngModelChange) 中,我想将值 returned 从 getStateList() 分配给一个变量,但它只是调用函数并且 return 值未绑定到变量.
您可以简单地在 getStateList 函数内部赋值
<select [(ngModel)]="country" (change)="getStateList(country)">
<option *ngFor="let c of countryList" [value]="c.Country.CountryID"></option>
</select>
组件内部
getStateList(country : any){
this.stateList = (getData);
}