Article From:https://segmentfault.com/q/1010000011711140
Question:
<input ng-if="mainRisk.kindCode!=='D12'"
                   type="checkbox"
                   ng-model="mainRisk.choosed"
                   ng-change="selectMainCoverage(mainRisk);selectRequired();setQuantity(mainRisk);clearmainRiskPrice(mainRisk);clearAllPrice();"
                   ng-required="orRequiredBI"
                   />

Trigger code:

$("input").click()

The effect is only selected, but it does not trigger the ng-change () method.

Answer 0:

I am just a porter of code.
The code is as follows:

$timeout(function() {
            var el = document.getElementById('first');
            angular.element(el).triggerHandler('click');
        }, 0);

Points to note:
1.$timeout injection is needed.
2.elIt’s a DOM element. It is not a JQuery element.
3.angular.element(el).triggerHandler(‘click’)It only triggers events, but does not trigger the click () method, such as el, which is a checkbox, and this code does not let him check it, and needs to do something else.

Similar Posts:

    None Found

Leave a Reply

Your email address will not be published. Required fields are marked *