Gerald Mathabela Gerald Mathabela - 4 years ago 123
jQuery Question

How to call a JQuery event within AngularJS function

Assuming validation is successful, how do i then call this Jquery event...

<script>
$('#login').click(function() {
//blah blah blah...
});
</script>


From this AngularJS function

<script>
// create angular app
var validationApp = angular.module('validationApp', []);

// create angular controller
validationApp.controller('mainController', function($scope) {

// function to submit the form after all validation has occurred
$scope.submitForm = function() {

// check to make sure the form is completely valid
if ($scope.userForm.$valid) {
// Call my Jquery function here
}

};

});
</script>

Answer Source

jQuery and AngularJS can work together but it is not good practice. You could use the built-in AngularJS ng-click to fire the onClick event and apply a function to it as follows:

<div id="login" ng-click="loginScriptToRunOnClick()"> My Login Div </div>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download