0

I need show, hide using two buttons. my requirement is, when click -> Button A , it should be hide, Button B should be show when click -> Button B , it should be hide, Button A should be show.

i am tying to do it with some other conditions. please check my code.

    <button class="btn btn-primary btn-flat pull-right"
                ng-if='(detailCustomter.clientCustomer.customerFlag===false) && accessRights.includes("FLAG_CUSTOMER")'>
            <i class="ion ion-flag"></i> Button A
        </button>

        <button class="btn btn-danger btn-flat pull-right"
                ng-if='(detailCustomter.clientCustomer.customerFlag===true ) && accessRights.includes("UNFLAG_CUSTOMER")'>
            <i class="ion ion-flag"></i> Button B
        </button>

if you can do this using ng-if attribute, that's good.

4
  • why not just something more clear like: <button class="a" ng-if="condition"></button> <button class="b" ng-if="!condition"></button>and then update only the condition accordingly Commented Jul 10, 2019 at 8:31
  • more conditions in the ng-if Commented Jul 10, 2019 at 8:34
  • Possible duplicate of AngularJS toggle button Commented Jul 10, 2019 at 9:08
  • i want to using two buttons. not from one Commented Jul 10, 2019 at 9:45

1 Answer 1

0

You can have a variable that represents the current condition and change it's value to the opposite on click.

Of course you will need to adjust the condition to your application.

var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
  $scope.condition = true;
  $scope.toggle = function() {
    $scope.condition = !$scope.condition;
  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<div ng-app="myApp">
    <div ng-controller="myCtrl">
        <button class="btn btn-primary btn-flat pull-right"
                ng-click="toggle()"
                ng-if="condition">
            <i class="ion ion-flag"></i> Button A
        </button>
        <button class="btn btn-danger btn-flat pull-right"
                ng-click="toggle()"
                ng-if="!condition">
            <i class="ion ion-flag"></i> Button B
        </button>
    </div>
</div>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.