【问题标题】:TypeScript+AngularJs:- How to pass the parameters through ng-Change to typescript functionTypeScript+AngularJs:- 如何通过 ng-Change 传递参数到 typescript 函数
【发布时间】:2015-09-28 20:55:34
【问题描述】:

我已经使用 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);
             });

         }

如您所见,我是否获得了这两个值,所以我可以将相同的值发送到我的控制器。

【问题讨论】:

    标签: angularjs typescript typescript1.4 angularjs-ng-change typescript1.5


    【解决方案1】:

    我得到了答案,我们可以传递如下所示的参数:-

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-15
      • 2022-01-17
      • 1970-01-01
      • 2014-12-14
      • 2020-10-25
      • 2018-02-18
      • 1970-01-01
      • 2016-05-08
      相关资源
      最近更新 更多