-
-
Save tommcfarlin/3444d2be3556fc0c67036d5e3b2a6390 to your computer and use it in GitHub Desktop.
[WordPress] Triggering Angular Events with jQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('select[ng-model="schedule.payment_method"]').each(function() { | |
// For the purposes of this example, we're going to select the first option. | |
$(this) | |
.children('option:eq(1)') | |
.attr('selected', 'selected'); | |
// Make sure the select element reflects the change (as setting the option doesn't always do this properly). | |
$(this).val($(this).children('option:selected').attr('value')); | |
// Now use the Angular API's triggerHandler function to call the change. | |
angular.element($(this)).triggerHandler('change'); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<select class="form-control ng-pristine ng-untouched ng-valid ng-empty" ng-model="item.payment_method" ng-change="updatePaymentMethod(item)" ng-options="method.display_name for method in paymentMethods track by method.id"> | |
<!-- more to come --> | |
</select> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<select class="form-control ng-pristine ng-untouched ng-valid ng-empty" ng-model="item.payment_method" ng-change="updatePaymentMethod(item)" ng-options="method.display_name for method in paymentMethods track by method.id"> | |
<option value="?"></option> | |
<option value="1042" selected="selected">Card 1001 (01/18)</option> | |
</select> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('select['ng-model="item.payment_method"]').trigger('change'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment