javascriptangularjsdom-eventsangularjs-ng-clickjqlite

How to test if event.target.hasClass() using angularJS and jqlite?


After a click pass the event to ctrl. I want to write a conditional that will return true if the element.target has the class modal-click-shield

Question:

How can I use .hasClass() with event.target using angulars' jqlite?

Problem:

Currently I'm getting a type error saying that:

$scope.exitModal = function(event){
        // Return to current page when exiting the modal, via UI.
        // After state return, should set focus on the matching link.
        var target = event.target;
        console.log(target.hasClass('modal-click-shield'));
});

Error:

TypeError: undefined is not a function

Html:

  <div class="modal-click-shield" ng-click="exitModal($event)">
     <div ui-view="pdw"  class="product-container"></div>
  </div>

Solution

  • Your element from event.target is a regular HTMLElement, not the JQlite version. You need to do this to convert it:

    angular.element(event.target);