<!-- FOR BOOLEAN VALUES =============================== --> <!-- for true values --> <div ng-show="hello">this is a welcome message</div> <!-- can also show if a value is false --> <div ng-show="!hello">this is a goodbye message</div> <!-- FOR EXPRESSIONS =============================== --> <!-- show if the appState variable is a string of goodbye --> <div ng-show="appState == 'goodbye'">this is a goodbye message</div> <!-- FOR FUNCTIONS =============================== --> <!-- use a function defined in your controller to evaluate if true or false --> <div ng-hide="checkSomething()"></div>
hello
or goodbye
. You can do this, for example, in the Angular controller and the corresponding div
will be shown or hidden after downloading the application.ngClick
to set the goCats
variable to true
or false
. <a href ng-click="goCats = !goCats">Toggle Cats</a>
ng-show
. <img ng-src="http://i.imgur.com/vkW3Lhe.jpg" ng-show="goCats">
We use ng-src for images that are used in an angular application if the image is to be hidden. If you do not use this directive, the image will be shown at the time of downloading the application, and then disappears as soon as angular realizes that the image should be hidden.
ng-model
with the variable aminal
. Depending on the entered value, if there is a line, an image will be shown. <input type="text" ng-model="aminal">
<img ng-src="http://i.imgur.com/vkW3Lhe.jpg" ng-show="aminal == 'cat'">
// set the default value of our number $scope.myNumber = 0; // function to evaluate if a number is even $scope.isEven = function(value) { if (value % 2 == 0) return true; else return false; };
<!-- show if our function evaluates to false --> <div ng-show="isEven(myNumber)"> <h2>The number is even.</h2> </div> <!-- show if our function evaluates to false --> <div ng-show="!isEven(myNumber)"> <h2>The number is odd.</h2> </div>
Source: https://habr.com/ru/post/218465/
All Articles