in angularjs how to access the element that triggered the event?

前端 未结 7 1419
-上瘾入骨i
-上瘾入骨i 2020-12-23 00:19

I use both Bootstrap and AngularJS in my web app. I\'m having some difficulty getting the two to work together.

I have an element, which has the attribute data

7条回答
  •  北荒
    北荒 (楼主)
    2020-12-23 00:44

    There is a solution using $element in the controller if you don't want to create another directive for this problem:

    appControllers.controller('YourCtrl', ['$scope', '$timeout', '$element',
            function($scope, $timeout, $element) {
    
        $scope.updateTypeahead = function() {
           // ... some logic here
           $timeout(function() {
               $element[0].getElementsByClassName('search-query')[0].focus();
               // if you have unique id you can use $window instead of $element:
               // $window.document.getElementById('searchText').focus();
           });
        }
    }]);
    

    And this will work with ng-change:

    
    

提交回复
热议问题