Alyssa Alyssa - 1 year ago 108
AngularJS Question

test if I clicked a button before redirecting AngularJS

I have a div which contains ng-click to be redirected to another page to show details, but in this div I have a button (Follow) and When I click on the button I should stay on the same page
enter image description here

<div class="panel-body" style="background-color: white;" ng-click="goToFacilitatorP(facilitator.username)">
<div class="col-md-2 col-xs-2">
<img class="img-thumbnail" data-ng-src="data:image/PNG;base64,{{facilitator.avatar}}" style="margin-top: 10px;height:120px;width:120px;" ng-show="true">
<div class="col-md-8 divtextCol">
<h3>{{facilitator.lastname}} {{facilitator.firstname}}, {{facilitator.title}}</h3>
<div class="col-md-2" style="margin-top: 50px;">
<button type="button" class="btn btn-link" ng-click="follow(facilitator);"><i class="fa fa-thumbs-o-up"></i> Suivre </button>

but here even if I click follow button, I'm redirected

var redirect= false;
$scope.goToFacilitatorP= function(){
console.log("function goToFacilitatorP()")
if(redirect == false){

I tried to use a variable to test but it doesn't work. Can someone help me please

Answer Source

Pass the event to your function, and prevent its propagation:

ng-click="follow(facilitator, $event)"


$scope.follow = function(facilitator, $event) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download