Is there a way to programmatically click an HTML <select> element?

I saw a javascript solution that looks something like this:

var select = document.getElementById('selectId')
select.click();

Is there an AngularJS approach / best practice to the same? (On top of my head you wrap the above ng-click code)

+4
source share
2 answers

Yes there is. Here's the angular equivalent of what you have in JavaScript

angular.element('#selectId').trigger('click');

Job example

+4
source

Any DOM manipulation in angular must be done inside the directive.

View

<div id="selectId" clickMe>content</div>

. - , , , dom. JQlite, .

app.directive('click-me', function(){
  return{
    link(scope, el, attr){
       $(el).trigger('click');
     }
  }
});
+1

Source: https://habr.com/ru/post/1608757/


All Articles