如何在http调用成功时禁用锚标记

san*_*aul 13 javascript anchor angularjs

任何人都可以帮我解决如何在http调用成功时禁用锚标记并在错误时启用它,反之亦然

这是我的Html页面

<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>
Run Code Online (Sandbox Code Playgroud)

这是我的控制器

$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();
Run Code Online (Sandbox Code Playgroud)

lev*_*evi 7

一个纯粹的AngularJS解决方案

在你的success回调中

.success(function(data){

    $scope.disableAnchor = true;

})
Run Code Online (Sandbox Code Playgroud)

在你的error回调中

.error(function(data){

    $scope.disableAnchor = false;

})
Run Code Online (Sandbox Code Playgroud)

你的锚标签

<a ng-click='clickAnchor($event)' href="#your_href"> <a/>
Run Code Online (Sandbox Code Playgroud)

然后在你的控制器中

$scope.clickAnchor = function($event){

   if ($scope.disableAnchor)
         $event.preventDefault()

}
Run Code Online (Sandbox Code Playgroud)

非纯AngularJS解决方案

在你的success回调中

.success(function(data){

   $("#your_anchor").on('click',function(e){
      e.preventDefault();
      return false
    })

})
Run Code Online (Sandbox Code Playgroud)

在你的error回调中

.error(function(data){

   $("#your_anchor").on('click',function(e){
    })

})
Run Code Online (Sandbox Code Playgroud)

我建议使用Pure Angularjs解决方案.