简体   繁体   English

如何将从函数调用返回的值分配给Angular 2中html内的变量

[英]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.

相关问题 如何将侦听器中 function 的返回值分配给变量并将其拆分 - how to assign a returned value from a function in a listener to variable and split it 无法将从 api 返回的数据值分配给 Angular 8 中的 class 变量 - Not able to assign data value returned from api to class variable in Angular 8 如何呈现通过Angular后端返回的变量内部传递的HTML代码 - How to render HTML code passed inside a variable that is returned from the backend in Angular 如何将从本地存储返回的值分配给变量以进一步使用 - how to assign the value returned from local storage to a variable for further use Angular / TS-如何从组件到服务调用函数并获取返回值 - Angular / TS - How to call a function from a component to a service and get a returned value Angular - 如何从对象内部调用函数 - Angular - How to call a function from inside an object 如何从 Angular 中的 http/async 调用为接口属性赋值? - How to assign value to interface property from http/async call in Angular? 将值分配给函数angular2中的内部变量 - Assign a value to an internal variable in a function angular2 如何从 angular 的构造函数中为变量赋值? - How I assign a value to variable from constructor in angular? 如何在角度6的http响应中为变量分配值? - How to assign value to a variable from http response in angular 6?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM