2

I have build an angularjs application. there are many places I used javascript console functions. now I want to use a single variable to turn off those console. I dont want to check the variable everytime whenever I use the console function. so I decided to make a service to handle that process.

Console factory

AppModule
.factory("$console", function (ENV) {
    function log (txt) {
        var args = arguments;
        if(ENV.debug) {
            console.log.apply(this, args);
        }
    }
    ...
    ...
});

And I called that function like the following way.

Controller

AppModule
.controller('CommonCtrl', function ($scope, $console
    $scope.personalInfo = function () {
            $scope.errmsg = false;
            getPersonalInfo(function (data) {
                if(!$scope.errmsg) {
                    $console.log("userdatainfo:",data);
                }

                ...
                ...
    })
});

All is working perfectly. But Only the problem is I can only see the line number of the factory file on inspect panel. I need to have the line number from where the factory function is getting called (like the line no of the above controller file). Please reply with valuable suggestion.

1
  • 1
    why dont you use console.trace() the same way like you did with the log? Commented Dec 1, 2016 at 10:15

1 Answer 1

2

This is a javascript feature and not specifically Angular. You can use arguments in a function like this. However the line number is not given but you get the caller name.

function Hello()
{
    console.log("caller is " + arguments.callee.caller.toString());
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.