即使我正在定义该事件并且它在Chrome中有效但它在Firefox中无效?
app.controller('lightbox_close_controller', ['$scope', '$rootScope', function($scope, $rootScope) {
$scope.close_rating_lightbox = function(event) {
if (!$(".lightbox").hasClass("mobile_ratebox")) {
event.stopPropagation();
$("#image_in_lightbox_inside").empty();
}
}
}
]);
答案 0 :(得分:17)
从ui
传递$event
喜欢
<button ng-click="close_rating_lightbox($event)">Click Me</button>
答案 1 :(得分:2)
在Angular 2中同样的问题,firefox在事件声明中更严格
//in chrom works fine
//in firefox throws event is undefined
@HostListener('click') onClick() {
console.info(event);
}
// to fix it you have to add
@HostListener('click', ['$event']) onClick(event) {
console.log(event)
}
答案 2 :(得分:1)
我发现如果在事件处理程序中忘记添加事件参数,也可能会出现此错误,即
onClicked(event){
}