简体   繁体   English

使用自定义事件扩展angular.js jQlite

[英]Extending angular.js jQlite with custom events

jQuery has a way to extend it with custom events. jQuery有一种使用自定义事件扩展它的方法。 Is it possible to extend angularjs jQueryLite in the similar manner? 是否可以以类似方式扩展angularjs jQueryLite? For example, if I would like to bind custom event in directive like this: 例如,如果我想在这样的指令中绑定自定义事件:

link: function (scope, element, attr) {
    // mousewheel would be custom event
    element.on("mousewheel", function (event) {
        // event handling
    });
}

Besides the list of jQuery API methods that are mimicked by jqLite, there's no documentation on jqLite internals. 除了jqLit​​e模仿的jQuery API方法列表之外,没有关于jqLit​​e内部的文档。 Because they are internal indeed and aren't meant to be extended. 因为它们确实是内部的,并不意味着要扩展。

Unlike jQuery, jqLite offers no way to provide custom events, it just wraps around DOM events . 与jQuery不同,jqLit​​e没有提供自定义事件的方法, 它只是包装DOM事件

It is possible to support custom events by patching angular.element.prototype.on , angular.element.prototype.off and angular.element.prototype.triggerHandler methods. 通过修补angular.element.prototype.onangular.element.prototype.offangular.element.prototype.triggerHandler方法,可以支持自定义事件。 But it is not advisable and is certainly not how the things are supposed to be done in Angular. 但这是不可取的,当然也不是应该在Angular中完成的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM