当放置多个表达式

时间:2016-05-13 07:02:12

标签: javascript angularjs

在一个场景中,我想使用无线电选择选项,明确选择之后,我希望用户进行确认,我已经使用了javascript的确认方法。确认选择后,只有下一个按钮才能启用。 看看下面的代码

HTML

  <body ng-controller="MainCtrl">
  <div ng-repeat="person in names">

    <input class="d-radio__input" ng-model="$parent.selectedCustomer" type="radio" ng-value="person" value="{{person.name}}" name="radio" ng-click="confirm()" required /> {{person.name}}

  </div>
  <button>Back</button>
  <button ng-click="next()" ng-disabled="selectedCustomer =='' && confirmation == 0 ">Next</button>
</body>

的Javascript

    app.controller('MainCtrl', function($scope) {
  $scope.selectedCustomer ='';
  $scope.confirmation=0;
  $scope.names = [{name:"Mayur"},{name:"Sameer"}];

                $scope.next = function () {
                    $scope.navigator =  $scope.navigator + 1 ;
                    console.log($scope.navigator)
                };
                $scope.confirm = function (location) {
                    var r = confirm("Click Ok to continue the offboarding process for (" + $scope.selectedCustomer.customerName + ")");
                    if (r === true) {
                        $scope.confirmation = 1;
                        console.log($scope.confirmation );
                    } else {
                        $scope.confirmation = 0;
                        console.log($scope.confirmation );
                    }
                }
});

因此,当我立即选择名称时,无论我在确认对话框中按什么,都会启用下一个按钮。但是,当我只保留一个条件表达式来评估ng-disabled时,它工作正常。  不知道如何在ng-disabled中添加多个条件。

如果我做错了,请告诉我。

查看Plunker

2 个答案:

答案 0 :(得分:1)

根据评论,因为它是禁用ng,并且你使用AND(&amp;&amp;),它只会在两者都为真时禁用,使用OR代替(||),按照普拉克:

<button ng-click="next()" ng-disabled="selectedCustomer == '' || !confirmation ">Next</button>

http://plnkr.co/edit/pGTuuE9RyGz7WOKSnClG?p=preview

答案 1 :(得分:1)

可能这是你的要求。

var app =angular.module('app' ,[])
app.controller('MainCtrl', function($scope) {
  $scope.selectedCustomer ='';
  $scope.confirmation=0;
  $scope.names = [{name:"Mayur"},{name:"Sameer"}];

                $scope.next = function () {
                    $scope.navigator =  $scope.navigator + 1 ;
                    console.log($scope.navigator)
                };
                $scope.confirm = function (location) {
                    var r = confirm("Click Ok to continue the offboarding process for (" + $scope.selectedCustomer.customerName + ")");
                    if (r === true) {
                        $scope.confirmation = 1;
                        console.log($scope.confirmation );
                    } else {
                        $scope.confirmation = 0;
                        console.log($scope.confirmation );
                    }
                }
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app='app' ng-controller="MainCtrl">
  <div ng-repeat="person in names">

    <input class="d-radio__input" ng-model="$parent.selectedCustomer" type="radio" ng-value="person" value="{{person.name}}" name="radio" ng-click="confirm()" required /> {{person.name}}

  </div>
  <button>Back</button>
  <button ng-click="next()" ng-disabled="selectedCustomer =='' || confirmation == 0 ">Next</button>
</body>