10

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();
            }
        }
    }

]);
2
  • It should be $event over here and pass the same in your html as well Commented Jun 11, 2015 at 10:12
  • show the related html Commented Jun 11, 2015 at 10:12

3 Answers 3

17

Pass $event from ui

like

<button ng-click="close_rating_lightbox($event)">Click Me</button>
Sign up to request clarification or add additional context in comments.

8 Comments

Thanks, it works. Just one more question regarding this. Even though I pass $event, in the function I can call event. Why is it working without the $ sign?
event property is override by angular $event so your code not works
Same behaviour like window to be $window, setTimeout be $timeout
function pass only value or reference if function has parameter then value or refrence will pass into that parameter according to position of passed data
Thanks. Had been hitting my head on the wall for past one hour.
|
2

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)
    } 

Comments

1

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){
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.