Angularjs have a $log directive, This directive major use for to identification debugging and program execution flow understand. It's also safe console message services.
$log Directive Methods
Method | Description | Example |
---|---|---|
log() | Can write a logger message from this method | $log.log($scope.message); |
info() | Can write a logger message for your infomation | $log.info($scope.message); |
warn() | Can write a logger message for warning | $log.warn($scope.message); |
error() | Can write a logger message for error | $log.error($scope.message); |
debug() | Can write a logger message for debug | $log.debug($scope.message); |
$log Example:
var app = angular.module("LogApp",[]);
app.controller("LogCtrl",function($scope, $log){
$scope.message = "This is sample implementation of $log directive";
$log.log($scope.message);
$log.info($scope.message);
$log.warn($scope.message);
$log.error($scope.message);
$log.debug($scope.message);
});
$log HTML
<div ng-app="LogApp">
<div ng-controller="LogCtrl">
</div>
</div>
Result:
Result will open any browser and inspect mode console only show the result or press F12 show the console log.
Comments
Post a Comment