mikemclin / angular-acl

Role-based permissions for AngularJS
196 stars 49 forks source link

Cannot read property 'split' of undefined at aclShowWatchAction #29

Open roselleebarle04 opened 7 years ago

roselleebarle04 commented 7 years ago

In watching attrs.aclShow, we should check if value is not null

screen shot 2017-07-11 at 6 54 20 am
lannodev commented 7 years ago

Hi @roselleebarle04 I change the code in angular-acl.js for this and fix my problem ;) I hope this resolve your problem

.directive('aclShow', function (AclService) {
  return {
    restrict: 'A',
    link: function (scope, element, attrs) {
      scope.$watch(attrs.aclShow, function aclShowWatchAction(value) {
        var permissions, can;
        permissions = attrs.aclShow;
        can = AclService.can(permissions);
        if (!can) {
          element.addClass(NG_HIDE_CLASS);
        } else {
          element.removeClass(NG_HIDE_CLASS);
        }
      });
    }
  };
});
mikemclin commented 7 years ago

@roselleebarle04 I am making it so null values cause the element not to show.

mikemclin commented 7 years ago

This fix is in the 0.1.10 release

lannodev commented 7 years ago

Hi @mikemclin, I think this dont fix the problem =[

image

mikemclin commented 7 years ago

@luciano-work does this work for you?

.directive('aclShow', function (AclService) {
  return {
    restrict: 'A',
    link: function (scope, element, attrs) {
      attrs.$observe('aclShow', function aclShowWatchAction(value) {
        var permissions, can;
        if (!value) {
          element.addClass(NG_HIDE_CLASS);
          return;
        }
        permissions = value.split(',');
        can = AclService.canAny(permissions);
        if (!can) {
          element.addClass(NG_HIDE_CLASS);
        } else {
          element.removeClass(NG_HIDE_CLASS);
        }
      });
    }
  };
});
lannodev commented 7 years ago

Doesn't work for me =( I have received an error in this code line: permissions = value.split(',');

ivanvastag commented 7 years ago

Hi, we are having the same issue with this. Still not getting any values from value attribute.