Can anyone help me with how to disable anchor tag on http call success and enable it on error and vice versa
This is my Html page
<a href="#" id="register_pointer" data-toggle="modal" data-target="#myModal1">
<div class="plus">
<i class="fa fa-2x fa-plus"></i>
</div>
<div class="register">
<h4>Create</h4>
<p>New Account</p>
</div>
</a>
This is my controller
$scope.MqUser=[];
$scope.getMqUser = function() {
usSpinnerService.spin('spinner-1');
MQDetailsService.getUserDetails().success(function(data, status) {
console.log(data);
usSpinnerService.stop('spinner-1');
$scope.createQ = false;
$scope.MqUser = data;
console.log("Success in getting the user list");
console.log($scope.MqUser);
//I want the anchor tag to get disabled here using angular directive.
}).error(function(data,status){
//I want the anchor tag to get enabled here using angular directive.
$scope.createQ = true;
console.log(data);
if(status == 0){
$scope.networkError();
}
else{
$scope.fetchuserFail(data.message);
}
usSpinnerService.stop('spinner-1');
console.log("Failed to load the user list "+status);
})
}
$scope.getMqUser();
Disable HTML Anchor Tag with CSS The best way to disable a link tag is by using the CSS property pointer-events: none; . When you apply pointer-events: none; to any element, all click events will be disabled. Because it applies to any element, you can use it to disable an anchor tag.
Simply disable default browser behaviour using preventDefault and pass the event within your HTML.
Yes, disabled isn't supported attribute by the anchor tab, but the CSS attribute selector does find it and so does jQuery's.
The anchor element is used to link to another page or to a certain part of the page if you use its ID. And The link tag defines a link between a document and an external resource. The link tag is used to link to external style sheets.
A pure AngularJS solution
In your success
callback
.success(function(data){
$scope.disableAnchor = true;
})
In your error
callback
.error(function(data){
$scope.disableAnchor = false;
})
Your anchor tag
<a ng-click='clickAnchor($event)' href="#your_href"> <a/>
Then in your controller
$scope.clickAnchor = function($event){
if ($scope.disableAnchor)
$event.preventDefault()
}
A non pure AngularJS solution
In your success
callback
.success(function(data){
$("#your_anchor").on('click',function(e){
e.preventDefault();
return false
})
})
in your error
callback
.error(function(data){
$("#your_anchor").on('click',function(e){
})
})
I recommend using Pure Angularjs solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With