David Hemsey
David Hemsey

Reputation: 277

Angular - Hide a button when clicking without using ng-show or ng-hide

I would like to hide a button in my form, once it's submitted and everything is working fine, I need to hide it and show something else, is there a way to do in my controller:

this.show= false; 

Or do I need to add ng-show to the button and implement a variable to set to hide it?

Upvotes: 2

Views: 171

Answers (4)

may lee
may lee

Reputation: 3

in controller

$scope.condition = true;
$scode.activeCondition = function (con) {
    $scope.condition = !con;
};

in html

<button type="button" ng-class="{'active': condition}" ng-click="activeCondition(condition)">

Upvotes: 0

Michel
Michel

Reputation: 28359

Instead of adding new variables, why not using what is already designed for that. In the angular object representing your form, there is a $submitted property. Therefore, providing your form is named myForm, something like that should do the trick:

<button ng-if="!myForm.$submitted">Button</button>

See official guide about forms in angular

Upvotes: 1

marco alves
marco alves

Reputation: 1717

Other option would be to use ng-style to do the job:

Upvotes: 0

Lucas
Lucas

Reputation: 10313

You could use ng-class:

ng-class="{'some-class': !some.object.user, 'some-other-class': some.object.user}"

Upvotes: 2

Related Questions