I study js framework Angular. Using the ng-click directive - I want to get an event object (they clicked on it) I know that jQquery uses $(this) . But how on angular to address event object by the convenient decision?

 categoriesApp.controller('categoriesController', function($scope, $http){ $http.post('/user/GetCats').success(function(data){ $scope.categories = data; }); $scope.show = function() { if($(this).hasClass()) { //.......some code } } }); 
 <input type="text" class="for-open-in53" placeholder="Укажите специализацию" ng-click="show($event)"> 
  • $scope.show = function(e){} in the argument will be passed to the DOM, as I understand it. Or an object that has a link to it. For example, e.target - oshliaer

3 answers 3

All DOM manipulations in Angularjs should be done through directives:

 app.directive('someDirName', function() { return { restrict: 'AE', link: function (scope, element, attrs) { element.on('click',function(){ // элемент события ↓ console.log( element ); }); } } }); 

    You can like this:

     $scope.show = function(e){ console.log(e) $(e.currentTarget).html('Дед Мороз') } 

    e - event object

    e.currentTarget - Event Object DOM

      ng-click="handler($event) - passing an event object ($ event) to HTML

       $scope.handler = function(event) { var animation = 'fadeInLeft'; //console.log(event); - смотрим что от него нам надо $(event.target).removeClass()..... и можно так