Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable anchor tags on http call success

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();
like image 764
sanmoy paul Avatar asked Mar 16 '15 05:03

sanmoy paul


People also ask

How do I turn off anchor tags?

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.

How can I disable href If onclick is executed?

Simply disable default browser behaviour using preventDefault and pass the event within your HTML.

Does anchor tag have disabled attribute?

Yes, disabled isn't supported attribute by the anchor tab, but the CSS attribute selector does find it and so does jQuery's.

What is the difference between anchor and tags?

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.


1 Answers

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.

like image 80
levi Avatar answered Nov 13 '22 06:11

levi