I'm using angularstrap's bs-select to do a drop down list select. And I want to programmatically trigger the drop down list button with JavaScript. Here is the plunker:
I want to use the button to trigger the drop down list. I've tried three methods:
- angular.element(document.querySelector("#test1")).triggerHandler('click');
it works with the elements with ng-click. But didn't work in bs-select
- document.getElementById("test1").click();
still didn't work for the triggerHandler('click')
- angular.element(document.querySelector("#test1")).triggerHandler('click'); $scope.$apply()
I thought it would be the problem that the scope need to digest again but it turns out that that is not the case.
And in angular strap the bs-select code is as follows:
$select.$onMouseDown = function(evt) {
    // Prevent blur on mousedown on .dropdown-menu
    evt.preventDefault();
    evt.stopPropagation();
    // Emulate click for mobile devices
    if(isTouch) {
        var targetEl = angular.element(evt.target);
        targetEl.triggerHandler('click');
    }
};
When it's mousdown it trigger the click on this button. So how can I do with it?
Thanks for the reply.
 
     
    