Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS: Error: event is undefined (Firefox only)

Even though I'm defining the event and it works in Chrome it does not work in 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();
            }
        }
    }

]);
like image 580
yodalr Avatar asked Jun 11 '15 10:06

yodalr


3 Answers

the same issue in Angular 2 , firefox is more strict in event declaration

//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)
    } 
like image 140
Dahar Youssef Avatar answered Oct 30 '22 18:10

Dahar Youssef


Pass $event from ui

like

<button ng-click="close_rating_lightbox($event)">Click Me</button>
like image 42
Anik Islam Abhi Avatar answered Oct 30 '22 16:10

Anik Islam Abhi


I discovered that you can also get this error if you forget to add the event argument if in the event handler, i.e.

onClicked(event){
}
like image 30
Stephen Paul Avatar answered Oct 30 '22 16:10

Stephen Paul