ng-if中的Angular add ng-show?

时间:2016-01-14 22:45:42

标签: javascript html angularjs

所以我希望这个输入只显示每个ng-if属性为true。目前的代码是:

<input type="button" class="naviaBtn naviaBlue" ng-if="ppt.Globals.hasDebitCard" ng-click="alertShow = (alertShow == 2 ? -1 : 2)"  value="outstanding swipes">

我可以以某种方式在ng-if表达式中添加ng-show,如果是,那么如何?我想也许是这样的:

ng-if="ppt.Globals.hasDebitCard ? ng-show='true'"

1 个答案:

答案 0 :(得分:0)

你确定可以!这是一个例子。

<!DOCTYPE html>
<html>
  <head>
    <title>Angular</title>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
    <script>
    angular.module("myApp", [])
    .controller("myCtrl", [function(){
      this.isOn = "on";
      this.isChecked = true;
    }]);
    </script>
  </head>
  <body ng-app="myApp" ng-controller="myCtrl as VM">
    <div ng-if="VM.isOn == 'on'" ng-show="VM.isChecked">
      Hi there
    </div>
    <div>ng-show: <input type="checkbox" ng-model="VM.isChecked" /></div>
    <div>ng-if:
      <input type="radio" name="myRadio" ng-model="VM.isOn" value="on" />On
      <input type="radio" name="myRadio" ng-model="VM.isOn" value="off" />Off
    </div>
  </body>
</html>