简体   繁体   English

自定义指令如何知道它是否已在另一个控件上单击

[英]How custom directive can know if it has been clicked on another control

I have created custom angular directive, something like type ahead.我创建了自定义角度指令,类似于提前输入。 I have angular ui datepicker on the screen too.我在屏幕上也有 angular ui datepicker。 I would like to close type ahead when I click on datepicker?我想在单击日期选择器时关闭提前输入?

How is it possible to catch an event within the custom directive when I click on datepicker?当我单击 datepicker 时,如何在自定义指令中捕获事件?

var app = angular.module('app', []);

app.constant('APP_EVENTS', {
    DATEPICKER_SHOWN: 'datepicker-shown'
});

app.directive('typeAhead', function ($rootScope, APP_EVENTS) {
    return {
        link: function (scope) {
            var deregister = $rootScope.$on(APP_EVENTS.DATEPICKER_SHOWN, function () {
                // hide type ahead
            });

            scope.$on('$destroy', deregister);
        }
    };
});

Now, use ng-click to broadcast the event of datepicker being shown so that typeahead can catch it.现在,使用 ng-click 广播显示的 datepicker 事件,以便预先输入可以捕获它。

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

相关问题 如何知道是否在另一页上单击了按钮? - How to know if button has been clicked on another page? 单击图像后,如何与另一个图像交换图像? - How can I swap an image with another, after it has been clicked? 如何知道指令的最后一个元素何时已在AngularJS中链接? - How to know when the last element of a directive has been linked in AngularJS? 如何知道在* ngFor循环中单击了哪个按钮? - How to know which button has been clicked in a *ngFor loop? 如何知道在jquery中点击了哪个id? - How to know which id has been clicked in jquery? JavaScript - 如何知道哪个对象被点击 - JavaScript - How to know which object has been clicked 在 stencil js 中,我如何检查按钮是否在不同类的另一个组件中被单击 - In stencil js, how can i check if button has been clicked in another component from a different class JS - 单击并打开另一个手风琴项时,如何关闭手风琴项? - JS - How can I make an accordion item close when another has been clicked on and opened? SAPUI5 - 如何获取我的自定义控件绑定到的模型的名称? - SAPUI5 - How can I get the name of the model to which my Custom Control has been bound? 我如何知道已经单击了哪一行? - How can I tell which row has been clicked?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM