如何在Angular中的文本框上执行事件?

时间:2016-12-28 20:42:42

标签: angularjs

我有一个文本框,显示当我点击复选框时我需要在其上创建一个事件,它可以让我将它绑定到来自DB的对象

HTML:

<div ng-repeat="feture in featureEnumArray">
    <input id="txtchkFet" type="checkbox" ng-model="feture.IsChecked" />
    {{feture.DisplayText}}
    <div ng-show="feture.IsChecked" >
        <input class="form-control" type="text" ng-model="feture.Value" ng-change="getFeatureID(feture)" id="txtValue" placeholder="Type Feature Value" />
    </div>
    <div class="label label-danger" ng-show="feture.IsChecked && !feture.Value">
        Type Value
    </div>
</div>

在Angular控制器中我做了这样:

  $scope.getFeatureID = function (feture) {
        if (feture.IsChecked) {
            $scope.Planfeature = angular.copy(feture);
            $scope.PlanFeatureTemp.FeatureID = $scope.Planfeature.ID;
            $scope.PlanFeatureTemp.Value = $scope.Planfeature.Value;
            $scope.Planfeature = [];
        }
        else {
            var index = $scope.JAdminPlan.PlanFeatureValues.indexOf(feture);
            $scope.JAdminPlan.PlanFeatureValues.splice(index, 1);
        }
        if (!$scope.$$phase) $scope.$apply();
    };

0 个答案:

没有答案