我已经使用 TypeScript 和 Angular Js 实现了一个模块。我已经使用 ng-options 填充了一个下拉列表,其中我也使用 ng-change。现在我想将所选值的索引和所选值发送到调用 ng-change 的函数并将该值设置为函数。所以我可以将这些值发送到我的 API 控制器。这是我的下拉代码:-
<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);
});
}
如您所见,我是否获得了两个值,因此我能够将其发送到我的控制器。