0

I am not too sure how to access a function declared in an interface inside of my constructor. I have a simple inferface

export interface ILog  {
    extendLog($delegate: any): ng.ILogService;
}

and for my constructor

export class LogConfig implements ILog{

    static $inject = ["$provide","$delegate"];
    constructor(public $provide : ng.auto.IProvideService,
                public $delegate: ng.ILogService
    ){
        $provide.decorator('$log',extendLog ); 
    }

    extendLog($delegate: any): ng.ILogService {

        var debugFunction = $delegate.debug;
        $delegate.debug = (...args: any[]): void => {
            var now = (new Date()).toLocaleTimeString();
            args[0] = now + ' - ' + args[0];
            debugFunction.apply(null, args);
        };
        return $delegate;
    }
}

extendLog is giving and error though

Cannot find name 'extendLog'

Am i even going about this the right way? Just trying to create a simple decorator.

3
  • 2
    maybe this.extendLog? Commented Dec 8, 2015 at 14:13
  • oh wow .. that is a n00b overlook right there. You can add the answer , ill accept Commented Dec 8, 2015 at 14:14
  • hehe, not necessary, minor typo/mistakes like that don't need answers imo. Commented Dec 8, 2015 at 14:54

1 Answer 1

1

Just use this.

$provide.decorator('$log',this.extendLog); 
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.