Kimmen Kimmen - 2 years ago 124
Javascript Question

extending angular global object in typescript

I'm using Angularjs and Typescript and I would like to extend the angular object with a custom function like this:


How do I go around and do this? I suspect I need to extend IAngularStatic somehow or can I use something like angular.prototype? (I'm not very experienced with extending javascript object to start with).

Maybe it's more proper to create an "angularHelperService" that get injected instead.

Answer Source

Just tell typescript about it by adding to the interface :

declare module ng {
    interface IAngularStatic {


I would prefer not to change the angular.d.ts as it's a third party component

You wouldn't put this in angular.d.ts. You would put this in your globals.d.ts (or vendor.d.ts) to document how you are customizing the vendor libraries (here angular) you are using in your project.

Remember: Interfaces are open ended.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download