Ng-If-3

 

In this example, we have div with ng-if="!vm.IsShow" and By default value of vm.IsShow is false, So on the basis of vm.IsShow value div element will show or hide. On button click, We are using ng-click like ng-click="vm.IsShow=!vm.IsShow" so that will change the value of vm.IsShow variable and make div visible or hidden.

 
 
 
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Welcome to LearnKode - A code learning platform</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> </head> <body ng-app="initExample"> <div ng-controller="ExampleController as vm"> <div ng-if="!vm.IsShow"> <input type="button" class="btn btn-primary" ng-click="vm.IsShow=!vm.IsShow" value="Login"> <p>Please Login</p> </div> <div ng-if="vm.IsShow"> <button class="btn btn-primary" ng-click="vm.IsShow=!vm.IsShow">Logout</button> <p>Welcome !</p> </div> </div> <script> var app = angular.module("initExample", []); app.controller('ExampleController', ['$scope', function ($scope) { var vm = this; }]); </script> </body> </html>
Output