AngularJS-$log-2

 
In this example, It will compare two values and generate log message according to condition as if values are equal log message is info and if val1 is greater than val2, code generate error message and so on. See the code snippet:
 
 
 
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Welcome in the AngularJS</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script> </head> <body ng-app="app"> <div ng-controller="$logController"> <label> Number1: <input type="number" ng-model="val1" ng-change="logMessage()" /> Number2:<input type="number" ng-model="val2" ng-change="logMessage()" /> </label> </div> </body> </html> <script> var app = angular.module("app", []); app.controller('$logController', ['$scope', '$log', function ($scope, $log) { $scope.$log = $log; $scope.val2 = 9; $scope.val1 = 10; $scope.logMessage = function () { if ($scope.val1 == $scope.val2) { $log.info("Both values are equal") } else if ($scope.val1 >= $scope.val2) { $log.error($scope.val1 + " is greater than value " + $scope.val2) } else if ($scope.val1 <= $scope.val2) { $log.warn($scope.val1 + " is lesser than " + $scope.val2) } else if ($scope.val1 != $scope.val2) { $log.info($scope.val1 + " is not equal to " + $scope.val2) } } }]); </script>
Output