如何绑定在AngularJS自定义事件?自定义、绑定、事件、AngularJS

2023-09-13 03:11:33 作者:_爱被你分成比例╯

我有一个自定义事件核心transitionend (实际上是由聚合物发射),我可以使用设置事件处理程序 document.addEventListener() 。但是,什么是最好的做法做到在AngularJS?

I have an custom event core-transitionend (actually fired by Polymer), and I can set an event handler using document.addEventListener(). But what's the best practice to do it in AngularJS?

或者,我可以明确地设置一个处理程序在DOM,即<造纸纹波上核心transitionend =输入()>< /纸纹波> ,但如何在AngularJS定义这个功能呢?

Or, I can explicitly set a handler in DOM, i.e. <paper-ripple on-core-transitionend="enter()"></paper-ripple>, but how to define this function in AngularJS?

推荐答案

拨弄的,在这里我创建了一个自定义指令其结合事件的元素

see this fiddle, here I have created a custom directive which binds the event to the element,

angular.module('HelloApp', [])
    .directive('customDir', function () {
        return {
            restrict: 'A',

            link: function(scope, element, attrs)      
            {
                element.bind("click",function()
            {
            alert("you clicked me");

        })
            }    


        }
    })

在你的情况下,您可以将您定义的事件简单地绑定到元素

In your case you can simply bind your defined event to the element