在扩展角打字稿全局对象 [英] extending angular global object in typescript
问题描述
我使用Angularjs和打字稿,我想用这样的自定义函数延长角的对象:
I'm using Angularjs and Typescript and I would like to extend the angular object with a custom function like this:
angular.executeAfterDigest(function(){...});
我如何去走一走,做到这一点?我怀疑我需要以某种方式延长IAngularStatic或者我可以使用类似angular.prototype? (我不是很延伸JavaScript对象,开始与经验)。
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).
也许是更恰当,以创建一个angularHelperService是那些获得注入代替。
Maybe it's more proper to create an "angularHelperService" that get injected instead.
推荐答案
只要告诉它打字稿通过向接口的https://github.com/borisyankov/DefinitelyTyped/blob/master/angularjs/angular.d.ts#L9
Just tell typescript about it by adding to the interface : https://github.com/borisyankov/DefinitelyTyped/blob/master/angularjs/angular.d.ts#L9
declare module ng {
interface IAngularStatic {
executeAfterDigest:Function;
}
}
更新
我想preFER不改变angular.d.ts因为它是一个第三方组件
您不会把这个 angular.d.ts
。你把这个在你的 globals.d.ts
(或 vendor.d.ts
),以记录您是如何定制供应商库(这里的角),你正在使用的您的项目。
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.
记住:在接口的打开结束的
这篇关于在扩展角打字稿全局对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!