Enable/Disable Anchor Tags using AngularJS

后端 未结 11 1592
一整个雨季
一整个雨季 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:51

    Have you tried using lazy evaluation of expressions like disabled || someAction()?

    Lets assume I defined something like so in my controller:

    $scope.disabled = true;
    

    Then I can disabling a link and apply inline styles like so:

    Higher Level
    

    Or better still disable a link and apply a class like so:

    Higher Level
    

    Note: that you will have a class="disabled" applied to DOM element by that statement.

    At this stage you just need to handle what you action GoTo() will do. In my case its as simple as redirect to associated state:

    $scope.GoTo = function (state) {
        if (state != undefined && state.length > 0) {
            $window.location.hash = state;
        }
    };
    

    Rather than being limited by ngDisabled you are limited by what you decide to do.

    With this technique I successfully applied permission level checking to enable or disable user access to certain part of my module.

    Simple plunker to demonstrate the point

提交回复
热议问题