-1
<a id="cli_id"
   ng-controller="EservlogsModalCtrl"
   ng-click="foo()">
   Create New Log
</a> 

I am triggering a click event using jQuery:

 $(document).ready(function () {
    $('#cli_id').click(function (){
        var customer = $('#4c609cf1bbb6c5080865df9cfc1fb649_mylogs_details_customer').val();
        if (customer == '')
        {
            return false;
        }
    }); 
}); 

I had expected that the ng-click would not fire when I return false. But I can see that it does fire.

How can I avoid the ng-click from firing in this case?

Buh Buh
  • 7,443
  • 1
  • 34
  • 61
vineet
  • 107
  • 8
  • 5
    dont use `ng-click` and `jquery` on same button. use the angular controller to manipulate the logic. what exactly you need? – Sravan Feb 20 '17 at 12:29
  • I want to click on button first of all read my java script for checking and then return true or false if false return then ng-click should be stop working . – vineet Feb 20 '17 at 12:32
  • Please not the commentary provided by @Sravan & please read this: http://stackoverflow.com/questions/14994391/thinking-in-angularjs-if-i-have-a-jquery-background – lin Feb 20 '17 at 12:39

1 Answers1

1

First of all DONT USE JQUERY WITH ANGULAR, instead angular controller to manipulate the logic.

This can be done in few ways, here is one of them.

If you have a field with id 4c609cf1bbb6c5080865df9cfc1fb649_mylogs_details_customer then use ng-model on it.

Example using ng-model:

<input type="text" id="4c609cf1bbb6c5080865df9cfc1fb649_mylogs_details_customer" ng-model="customer_details">

Controller:

app.controller('myCtrl', function($scope) {
    $scope.openlogsEservModal = function(param1,param2,param3,param4)
    {

        if ($scope.customer_details; == '') {
            // return false / Do nothing;
        }
        else
        {
         // write your logic here
        }
    }
});

If it is dynamic and if you cannot use ng-model,

In the method, openlogsEservModal check the condition you want to check using angular.element and do your logic.

Here is the controller, you can use like this,

Example without using ng-model::**

app.controller('myCtrl', function($scope) {
    $scope.openlogsEservModal = function(param1,param2,param3,param4)
    {
     var customer = angular.element('#4c609cf1bbb6c5080865df9cfc1fb649_mylogs_details_customer').val();
        if (customer == '') {
            // return false / Do nothing;
        }
        else
        {
         // write your logic here
        }
    }
});
Sravan
  • 18,467
  • 3
  • 30
  • 54