Introduction:

In this article we will learn how to use $log service in AngularJs or what is $log service in AngularJs or why use $log service in AngularJs with example.

Description:

AngularJs provide logging service $log, which logs the messages to the browser's console. The $log service provides different methods to log the error, information, warning or debug information. It can be useful in debugging and auditing.

following the Below different type  $log service methods:

log():Write a log message.

info():Write an information message.

warn():Write a warning message.

error():Write an error message.

debug():Write a debug message.

Example:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Log.aspx.cs" 
  Inherits="Example.Log" %>
<!DOCTYPE html>
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="Scripts/angular.min.js"></script>
</head>
 
    <body ng-app="myApp" >
    <div ng-controller="myController">
        <p>Please check the browser console for the logging information.</p>
    </div>
    <script>
        var myApp = angular.module('myApp', []);
        myApp.controller("myController", function ($log) {
            $log.log('This is log.');
            $log.error('This is error.');
            $log.info('This is info.');
            $log.warn('This is warning.');
            $log.debug('This is debugging.');
        });
    </script>
</body>
</html>

Output:

How to use $log service in AngularJs

I hope this article will help to you.

0 comments


Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

You may also like