[英]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.