[英]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>
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. 在(ngModelChange)中,我想将getStateList()返回的值分配给一个变量,但是它只是调用该函数,并且返回值未绑定到变量。
You can simply assign inside the getStateList function itself 您可以简单地在getStateList函数内部进行分配
<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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.