我怎样才能用ngclick替换ngmodel

时间:2015-03-18 14:49:33

标签: javascript angularjs

现在我的代码使用了ng-model:

<input type="checkbox" ng-model="padesVisual.selected">

但是,我需要更改为ng-click:

<li>
  <a href="#PAdES" aria-controls="PAdES" role="tab" data-toggle="tab"
     ng-click="VerificaPades(verifica)">PAdES</a>
</li>

我尝试使用此功能:

$scope.VerificaPades = function(verifica) {
    if ($scope.padesVisual.selected) {
        return true;
    } else {
        return false;
    }
}

1 个答案:

答案 0 :(得分:0)

下面的代码段演示了使用ng-click实现布尔切换的一种方法。感兴趣的主要是VerificadaPades函数,它实际上切换了布尔模型。

var eAssinatura = angular.module("pades", []);

eAssinatura.controller('AdicionarEditarFormatoAssinaturaDialogController', ['$scope',
function ($scope) {
       
        $scope.padesVisual = {
            positions: [],
            fields: [],
            selected: false,
            sealStamp: { isSelected: false, image: '' }
        }

        $scope.VerificaPades = function () {
            $scope.padesVisual.selected = !$scope.padesVisual.selected;
        }

       
    }
]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="pades" ng-controller="AdicionarEditarFormatoAssinaturaDialogController">
<ul class="nav nav-tabs" role="tablist">
  <li class="active">
    <a href="#CAdES" aria-controls="CAdES" role="tab" data-toggle="tab">CAdES</a>
  </li>
  <li>
    <a href="#PAdES" aria-controls="PAdES" role="tab" data-toggle="tab" ng-click="VerificaPades()">
      PAdES</a>
  </li>
</ul>
<div class="tab-content">
        <div role="tabpanel" class="tab-pane fade in active" id="CAdES">CAdES</div>
        <div role="tabpanel" class="tab-pane fade" id="PAdES">
            <div class="row" ng-show="padesVisual.selected">
              Selected
            </div>
        </div>
</div>
</div>