I have a strange problem with my AngularJS
project. I have 2 buttons
that trigger inputs
below.
<button type="button" class="btn btn-primary" data-ng-click="triggerInput('B1')">B1</button>
<input id="b1Input" type="file" accept="image/*" class="hide" onchange="angular.element(this).scope().changeImage(this)" />
<button type="button" class="btn btn-primary" data-ng-click="triggerInput('B2')">B2</button>
<input id="b2Input" type="file" accept="image/*" class="hide" onchange="angular.element(this).scope().changeImage(this)" />
I tried to debug the JS
code, but it seems to be okay. Unfortunatelly, Sometimes I have to click chosen button couple times (2-4) to make the input open. Maybe the jQuery
selector is bad?
Here's the code:
$scope.triggerInput = function (type) {
$timeout(function () {
var selector = "";
switch (type) {
case "B1":
selector = "b1Input";
break;
case "B2":
selector = "b2Input";
break;
}
$("input[id='" + selector + "']").trigger("click");
});
};