0

我已經使用TypeScript和Angular Js實現了一個模塊。我已經使用ng-options填充了一個下拉列表,其中im也使用了ng-change.Now我想將選定值的索引和選定的值發送到ng-change上調用的函數,並將該值設置爲功能。因此,我可以將這些值發送到我的API控制器。 這裏是我的下拉代碼: -TypeScript + AngularJs: - 如何通過ng參數傳遞 - 更改爲打印腳本功能

<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); 
      }); 

     } 

正如你可以看到,如果我有兩個值,以便即時通訊能夠在同一發送到我的控制器。

回答

0

我得到了答案,我們可以傳遞參數,如如下圖所示我: -

<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> 

在我的打字稿控制器: -

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); 
     });