Enable/Disable Anchor Tags using AngularJS

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

    Modifying @Nitin's answer to work with dynamic disabling:

    angular.module('myApp').directive('a', function() {
      return {
        restrict: 'E',
        link: function(scope, elem, attrs) {
          elem.on('click', function(e) {
            if (attrs.disabled) {
              e.preventDefault(); // prevent link click
            }
          });
        }
      };
    });
    

    This checks the existence of disabled attribute and its value upon every click.

提交回复
热议问题