AngularJs +打字稿: - 如何获得NG-选择所选指标值所选、如何获得、指标、AngularJs

2023-09-13 04:15:55 作者:这一枪叫心动

我米工作模块在那里我有检查条件面板的知名度,如果一个下拉的slected指数不等于0或-1比它会让我的面板否则将不可见的。我如何使用让我的下拉列表中选择索引值有点糊涂了 NG-选择 。我已经表明我下面的下拉code: -

I m working on module where I have check a condition for the visibility of a panel as if slected index of a dropdown is not equal to 0 or -1 than it will make visible to my panel else it will not. I am bit confused as how to get the selected index value of my dropdown using ng-select. I have shown my dropdown code below:-

 <div data-ng-app="CustomerNew" data-ng-controller="CreateCustomerCtrl as custom"  ng-init= getFormData(); >
<table>
<tr>
     <td>                                             
     <select id="accountselector" style="width: 100%;">
     <option value="0">--- Select an option ---</option>
    <option data-ng-repeat="acnt in listAccountTypes" value="{{acnt.id}}">{{acnt}}</option>
    </select>
    </td></tr>
</table>
</div>

下面是我的打字稿控制器

Here is my typescript controller

/// <reference path="../interface/interface.ts" />
/// <reference path="../../scripts/typings/jquery/jquery.d.ts" />
/// <reference path="../../scripts/typings/angularjs/angular.d.ts" />

module CustomerNew.controllers {
    export class CreateCustomerCtrl {
        static $inject = ['$scope', '$http', '$templateCache'];
        constructor(protected $scope: ICustomerScope,
            protected $http: ng.IHttpService,
            protected $templateCache: ng.ITemplateCacheService) {
            $scope.getFormData = this.getFormData;
        }
           public getFormData = (getFormData: any) => {
            this.$http.get(doAccountTypeUrl).
                success((data, status, headers, config) => {
                this.$scope.listAccountTypes = data["AccountCodesDisplayTypes"];
            }).
                error((data, status) => {
                debugger;
                console.log("In Error:-Request Failed");
                alert(status);
            });
        }  
    }
    var customerapp = angular.module("CustomerNew", []);
    customerapp
      .controller('CreateCustomerCtrl', CustomerNew.controllers.CreateCustomerCtrl);
    var doAccountTypeUrl = '/API/Create/GetLoadData';
}
</Controller>

条件,我有检查:

Condition Which i have to check:

if (listAccountTypes.SelectedIndex > -1 && listAccountTypes.SelectedValue != "0")
 {
 IntlCountryAddres objIntlCountryAddres = objIntlCountryAddressController.GetByCountryId(Convert.ToInt32(listAccountTypes.SelectedValue));
 if (objIntlCountryAddres != null && objIntlCountryAddres.id > 0)
    {
       pnlBillingCountry.Visible = true;
       LoadBillingInfo(objIntlCountryAddres);
    }
     }
 else
    {
      pnlBillingCountry.Visible = false;
    }

注:-I正在检查在页面加载这个条件我得到如下格式的数据: -

Note:-I am checking this condition on page load I am getting data in below format:-

推荐答案

不具备选项内联:

<select id="accountselector" style="width: 100%;">
 <option value="0">--- Select an option ---</option>

而是使用 NG-选项 NG-模型

<select id="accountselector" style="width: 100%;" ng-options="check docs" ng-model="check docs"></select>

检查文档: https://docs.angularjs.org/api/ng/指令/ ngOptions