I have been given an old Angular.js app to maintain and I have been tracking an elusive bug that made me use the $log service to display a lead on the console. I used $log since the very same IDE VSC tells me that using console.log is a bad practice. Well console.log works and when I use $log.log or anything derivative out of $log it just shows: "TypeError: s is undefined", not what I was trying to display. Now I am super curious, even though I can use console.log just fine I want to know what in the world is going on. My code:
import angular from "angular";
class StuffController{
constructor($scope,$window,usuarioService,userSession,$log,$document){
this.$scope=$scope;
this.$log=$log;
this.debug;
this.debug = function(model){
try{
$log.log("this is a log for: " + model);
$log.debug("this is a debug for: " + model);
}catch(e){
console.log("This is a console log for: " + model +" "+ e);
}
}
}
}
stuffController.$inject=["$scope","$window","usuarioService","userSession"];
angular.module("webapp").controller("StuffController",StuffController);
When I use the debug function on any ng-change I get this on the console: This is a console log for: radio TypeError: s is undefined