Enable/Disable Anchor Tags using AngularJS

后端 未结 11 1549
一整个雨季
一整个雨季 2020-12-01 05:45

How do I enable/disable anchor tags using the directive approach?

Example:

  1. while clicking on edit link, create & delete needs to be disabled or g
11条回答
  •  温柔的废话
    2020-12-01 06:31

    Make a toggle function in the respective scope to grey out the link.

    First,create the following CSS classes in your .css file.

    .disabled {
        pointer-events: none;
        cursor: default;
    }
    
    .enabled {
        pointer-events: visible;
        cursor: auto;
    }
    

    Add a $scope.state and $scope.toggle variable. Edit your controller in the JS file like:

        $scope.state='on';
        $scope.toggle='enabled';
        $scope.changeState = function () {
                    $scope.state = $scope.state === 'on' ? 'off' : 'on';
                    $scope.toggleEdit();
                };
        $scope.toggleEdit = function () {
                if ($scope.state === 'on')
                    $scope.toggle = 'enabled';
                else
                    $scope.toggle = 'disabled';
            };
    

    Now,in the HTML a tags edit as:

    CREATE
    EDIT
    DELETE

    To avoid the problem of the link disabling itself, change the DOM CSS class at the end of the function.

    document.getElementById("create").className = "enabled";
    

提交回复
热议问题