How can I trigger the click event of another element in ng-click using angularjs?

前端 未结 12 1653
耶瑟儿~
耶瑟儿~ 2020-12-03 04:05

I\'m trying to trigger the click event of the element from the button.



        
12条回答
  •  忘掉有多难
    2020-12-03 04:54

    If your input and button are siblings (and they are in your case OP):

    
    
    
    

    Use a directive to bind the click of your button to the file input like so:

    app.directive('uploadfile', function () {
        return {
          restrict: 'A',
          link: function(scope, element) {
    
            element.bind('click', function(e) {
                angular.element(e.target).siblings('#upload').trigger('click');
            });
          }
        };
    });
    

提交回复
热议问题