The directive ng-hide
hides the element depending on the output of the expression specified in the attribute.
Example:
<button ng-hide="esconderBotao">Botao 1</button>
Case the variable esconderBotao
is declared in scope and is TRUE (or equivalent) the button will be hidden (class . ng-Hide is added to the element).
Another example:
angular.module('App', [])
.controller('ExemploController', ['$scope', function($scope) {
$scope.esconderBotao1 = false;
$scope.botao1 = function() {
alert('Ok!');
}
}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="App">
<div ng-controller="ExemploController">
<button ng-click="botao1()" ng-hide="esconderBotao1">Botao 1</button>
<br /><br />
<button ng-click="esconderBotao1 = true" ng-show="!esconderBotao1">Esconder botão 1</button>
<button ng-click="esconderBotao1 = false" ng-show="esconderBotao1">Mostrar botão 1</button>
</div>
</div>
In the above example, by clicking the "Hide" button, the variable esconderBotao1
(see ng-click) is set to TRUE and button 1 is hidden automatically. By clicking the "Show" button the variable esconderBotao1
is set to FALSE and button 1 is automatically displayed.
Note: If you do not set a value for the variable in the scope the element ng-Hide will not hide the element by default.
ngIf
serves to create or recreate elements, not simply display or hide.– Vinícius Gobbo A. de Oliveira