How to trigger ng-change in directive test in AngularJS

后端 未结 5 1054
情歌与酒
情歌与酒 2021-01-01 15:13

I have the following AngularJS directive that creates an input element. Input has ng-change attribute that runs doIt() function. In my

5条回答
  •  甜味超标
    2021-01-01 15:52

    Have been trying to get this to work, but failed on every attempt. Finally concluded that my ng-model-options with a debounce setting on the onUpdate, was the problem.

    If you have a debounce, make sure that you flush with the $timeout service. In angular mock, this timeout service has been extended with a flush operation, which handles all unfulfilled requests/actions.

        var tobetriggered = angular.element(element[0].querySelector('.js-triggervalue'));
        tobetriggered.val('value');
        tobetriggered.trigger('change');
        $timeout.flush();
    

提交回复
热议问题