Angularjs Examples

AJS Examples


AngularJS $log Service

The AngularJS $log service is used to write error, info, warning and debugging into the browser's console. The $log service is used to simple simplify debugging and troubleshooting. It includes all the methods to log the error, information, warning and debug information.

Syntax

$log.log('Log Message.');
$log.error('Log Error.');
$log.info('Log Info.');
$log.warn('Log Warning.');
$log.debug('Log Debugging.');

AngularJS $log Service Example

<!DOCTYPE html>
<html>
<head> <!-- www.techstrikers.com -->
 <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.1/angular.min.js"></script> 
    <meta charset="utf-8">
    <title>AngularJS $log Example</title>
  <script>
var app = angular.module('app', []);
    app.controller("LogController", function ($scope,$log) {

      $scope.LogMessage = function()
      {
         $log.log($scope.message);      
      }
      $scope.LogError = function()
      {
         $log.error($scope.error);    
      }
      $scope.logInfo = function()
      {
         $log.info($scope.info);      
      }
      $scope.logWarning = function()
      {
         $log.warn($scope.warning);     
      }
      $scope.logDebug = function()
      {
         $log.debug($scope.debug);     
      }
    });
</script>
</head>
<body style="background-color:#DDE4E9;">
  <fieldset style="background-color:#DDE4E9;">            
    <legend>AngulerJS $log Service Example</legend> 
  <div ng-app="app">      
    <div ng-controller="LogController"> 
      <p>Reload this page with open console, enter text and hit the log buttons</p>
      Log Message:        
        <input type="string" ng-model="message">        
        <button ng-click="LogMessage()">Log Message</button></br>     
      Log Error:      
        <input type="string" ng-model="error">        
        <button ng-click="LogError()">Log Error</button> </br>     
      Log Info:    
      <input type="string" ng-model="info">  
        <button ng-click="logInfo()">Log Info</button> </br>
    Log Warning:      
        <input type="string" ng-model="warning">        
        <button ng-click="logWarning()">Log Warning</button> </br>     
      Log Debug:    
    <input type="string" ng-model="debug">  
        <button ng-click="logDebug()">Log Debug</button> </br>
    </div>      
</div>
 </fieldset> 
</body>
</html>
See Live Example