AngularJs针对多个条件评估表达式

时间:2013-12-10 21:54:47

标签: javascript angularjs

是否可以在2个条件为真时调用函数?

<a id="Send" ng-click="(model.condition1 and model.condition2) || doSomething()"></a>

2 个答案:

答案 0 :(得分:3)

处理实际功能:

ng-click="doSomething()"

 $scope.doSomething = function() {
     if (!model.condition1 and model.condition2)
         return
     //do stuff
  }

答案 1 :(得分:2)

理想情况下,您应该保持逻辑远离template。但这应该有效:

<a id="Send" 
   ng-click="model.condition1 && model.condition2 && doSomething()"></a>

示例

<form name="myForm" ng-controller="Ctrl">
    userType: <input name="input" ng-model="userType" required>

    <a id="Send" 
       ng-click="myForm.$valid && userType.length() > 2 && doSomething()"></a>
</form>