Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS $log.debug is not a function

I'm a bit frustrated because I can't figure out whats up with the AngularJS $log service. I don't use it often but I have it working on another part of my site, the only reason I could think it wouldn't be working would be something to do with the block scope inside the then function.
In my console I get the following error when trying to run $log.debug:

TypeError: $log.debug is not a function
    at analysis.client.controller.js:23
    at processQueue (angular.js:14551)
    at angular.js:14567
    at Scope.$get.Scope.$eval (angular.js:15830)
    at Scope.$get.Scope.$digest (angular.js:15641)
    at angular.js:15869
    at completeOutstandingRequest (angular.js:5387)
    at angular.js:5659

Heres my analysis.client.controller.js file:

'use strict';

angular.module('analysis').controller('AnalysisController', ['$scope', '$timeout', '$mdSidenav', '$mdComponentRegistry', '$log', 'Authentication',
    function($scope, $timeout, $mdSidenav, $mdComponentRegistry, $log, Authentication) {
        $scope.user = Authentication.user;

        // Option #1
        //
        // $scope.isOpen = function() { return $mdSidenav('right').isOpen(); };
        // $scope.toggle = function() { $mdSidenav('right').toggle() };


        // Option #2 - See https://github.com/angular/material/issues/974

        $scope.toggle = angular.noop;
        $scope.isOpen = function() {
            return false;
        };

        $scope.toggleLeft = function() {
            $mdSidenav('left').toggle()
                .then(function() {
                    $log.debug('toggle left is done');
                });
        };
    }

]);

Thanks in advance for any help!

like image 862
Daniel Kobe Avatar asked Jan 09 '23 02:01

Daniel Kobe


2 Answers

The debug method is not enabled by default because not all browsers support console.debug, but you can enable it in the configuration phase of your app with the $logProvider.

'use strict';

angular.module('analysis')
  .config(function($logProvider){
    $logProvider.debugEnabled(true);
  })
  .controller('AnalysisController', function(
    $scope,
    $timeout,
    $mdSidenav,
    $mdComponentRegistry,
    $log,
    Authentication
  ) {
    $scope.user = Authentication.user;

    // Option #1
    //
    // $scope.isOpen = function() { return $mdSidenav('right').isOpen(); };
    // $scope.toggle = function() { $mdSidenav('right').toggle() };


    // Option #2 - See https://github.com/angular/material/issues/974

    $scope.toggle = angular.noop;
    $scope.isOpen = function() {
      return false;
    };

    $scope.toggleLeft = function() {
      $mdSidenav('left').toggle().then(function() {
        $log.debug('toggle left is done');
      });
    };
  });
like image 179
Chev Avatar answered Jan 10 '23 17:01

Chev


$log's debug method is disabled by default. You need to enable $log from app config phase like below.

app.config(function($logProvider){
  $logProvider.debugEnabled(true);
});
like image 31
Pankaj Parkar Avatar answered Jan 10 '23 19:01

Pankaj Parkar