TypeScript+AngularJs:- 如何通过 ng-Change 传递参数到 typescript 函数
TypeScript+AngularJs:- How to pass the parameters through ng-Change to typescript function
我已经使用 TypeScript 和 Angular Js 实现了一个模块。我使用 ng-options 填充了一个下拉列表,其中我使用 ng-change too.Now 我想将所选值的索引和所选值发送到 ng-change 上调用的函数并将该值设置为函数 too.so 我可以将这些值发送到我的 API 控制器。
这是我的 DropDown 代码:-
<div data-ng-app="CustomerNew" data-ng-controller="CreateCustomerCtrl as custom" ng-init="getFormData();">
<tr>
<td>Billing Type:</td>
<td>
<select id="listBillingType"
ng-change="listBillingTypeselectedindexchange((index.Of(blngtypee),(custom.listBillingType))"data-ng-options="blngtype as blngtypee for (blngtype,blngtypee) in listBillingType"
data-ng-model="custom.listBillingType"
style="width: 182px !important; height: 34px;">
<option value="">Choose an option {{optional ? '(optional)' : ''}}</option>
</select>
</td></tr>
</div>
这是我的打字稿控制器代码:-
public listBillingTypeselectedindexchange = (listBillingTypeselectedindexchange: any) => {
debugger;
var data = {
index:here is want to set the value of my index
selectedvalue:here i want to set the value of my selected value
}
this.$http.post(doAccountTypeUrl,data).
success((data, status, headers, config) => {
debugger;
}).
error((data, status) => {
debugger;
console.log("In Error:-in index");
alert(status);
});
}
如您所见,如果我获得了两个值,那么我可以将它们发送到我的控制器。
我得到了答案,我们可以传递如下所示的参数:-
<div data-ng-app="CustomerNew" data-ng-controller="CreateCustomerCtrl as custom" ng-init="getFormData();">
<tr>
<tr>
<td>Billing Type:</td>
<td>
<select id="listBillingType" ng- change="listBillingTypeselectedindexchange(custom.listBillingType)"
data-ng-options="blngtype as blngtypee for (blngtype,blngtypee) in listBillingType"
data-ng-model="custom.listBillingType" style="width: 182px !important; height: 34px;">
<option value="">Choose an option {{optional ? '(optional)' : ''}}</option>
</select>
</td>
</tr>
</div>
在我的 TypeScript 控制器中:-
public listBillingTypeselectedindexchange = (Item) => {
debugger;
var data = {
selecteditem: Item
}
this.$http.post(Url,data).
success((data, status, headers, config) => {
}).
error((data, status) => {
console.log("In Error");
alert(status);
});
我已经使用 TypeScript 和 Angular Js 实现了一个模块。我使用 ng-options 填充了一个下拉列表,其中我使用 ng-change too.Now 我想将所选值的索引和所选值发送到 ng-change 上调用的函数并将该值设置为函数 too.so 我可以将这些值发送到我的 API 控制器。 这是我的 DropDown 代码:-
<div data-ng-app="CustomerNew" data-ng-controller="CreateCustomerCtrl as custom" ng-init="getFormData();">
<tr>
<td>Billing Type:</td>
<td>
<select id="listBillingType"
ng-change="listBillingTypeselectedindexchange((index.Of(blngtypee),(custom.listBillingType))"data-ng-options="blngtype as blngtypee for (blngtype,blngtypee) in listBillingType"
data-ng-model="custom.listBillingType"
style="width: 182px !important; height: 34px;">
<option value="">Choose an option {{optional ? '(optional)' : ''}}</option>
</select>
</td></tr>
</div>
这是我的打字稿控制器代码:-
public listBillingTypeselectedindexchange = (listBillingTypeselectedindexchange: any) => {
debugger;
var data = {
index:here is want to set the value of my index
selectedvalue:here i want to set the value of my selected value
}
this.$http.post(doAccountTypeUrl,data).
success((data, status, headers, config) => {
debugger;
}).
error((data, status) => {
debugger;
console.log("In Error:-in index");
alert(status);
});
}
如您所见,如果我获得了两个值,那么我可以将它们发送到我的控制器。
我得到了答案,我们可以传递如下所示的参数:-
<div data-ng-app="CustomerNew" data-ng-controller="CreateCustomerCtrl as custom" ng-init="getFormData();">
<tr>
<tr>
<td>Billing Type:</td>
<td>
<select id="listBillingType" ng- change="listBillingTypeselectedindexchange(custom.listBillingType)"
data-ng-options="blngtype as blngtypee for (blngtype,blngtypee) in listBillingType"
data-ng-model="custom.listBillingType" style="width: 182px !important; height: 34px;">
<option value="">Choose an option {{optional ? '(optional)' : ''}}</option>
</select>
</td>
</tr>
</div>
在我的 TypeScript 控制器中:-
public listBillingTypeselectedindexchange = (Item) => {
debugger;
var data = {
selecteditem: Item
}
this.$http.post(Url,data).
success((data, status, headers, config) => {
}).
error((data, status) => {
console.log("In Error");
alert(status);
});