Today i am going to share the code sample for angularjs ng-if else conditional Expression.
The angularjs not provide the if() {} else{} condition like others but we can achieve it by using the module.It is a collection
of control flow directives like:
1. ng-if
2. ng-if-else
3. ng-else
Example Code Sample
- <!DOCTYPE html>
- <html>
-
- <head>
- <script src="http://code.angularjs.org/1.2.0-rc.2/angularjs.js"></script>
- <script>
- function mainController($scope)
- {
- $scope.data =
- {
- FName: 'Yogendra',
- LName: 'Yadav'
- };
- }
- </script>
-
- <body ng-app>
- <div ng-controller="mainController">
- <h2>ng-if else in angularjs</h2>
- <div>
- <div ng-if="data.FName==='Yogendra'">
- Employee Name: {{FName}} {{LName}}
- </div>
- <div ng-if="data.FName===' '">
- Sample Code
- </div>
- </div>
- </div>
- </body>
-
- </html>