Articles → ANGULAR.JS → Ng-If Directive In Angular.JS

Ng-If Directive In Angular.JS







ng-if = “condition”




<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">
	<title></title>
	<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
	<script type="text/javascript">
	var app = angular.module('app', []);
	app.controller('myController', function($scope) {
		$scope.Voters = [{
			Name: "Karan",
			Age: 33
		}, {
			Name: "Anurag",
			Age: 16
		}, {
			Name: "Ritesh",
			Age: 34
		}];
	});
	</script>
</head>

<body>
	<form id="form1" runat="server">
		<div ng-app="app" ng-controller="myController">
			<table border="1">
				<tr ng-repeat="voter in Voters">
					<td> {{voter.Name}} </td>
					<td ng-if="voter.Age >= 18"> Eligible </td>
					<td ng-if="voter.Age < 18"> Not Eligible </td>
					<td> {{voter.Age}} </td>
				</tr>
			</table>
		</div>
	</form>
</body>

</html>





Output


Picture showing the output of the ng-if directive in angular.js

Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Thursday, May 28, 2015

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250