0

I have this directive for my ld Client. I tried to use it inside an ng-repeat but it wont work. What is the problem with this one? how can i make it work?

Tried to add the directive outside of ng-repeat and its working.

ldClient is a api variable in other module which returns true or false base on the flag variation.

Actually It doesnt even evaluate the directive like it not even calling it when its inside the ng-repeat

app.directive('flag', function (utilService) {
    return {
        restrict: 'A',
        link: function (scope, element, attrs) { 
          ldclient.on('ready', function() {
            var flag = false;         
            console.log(element);
            flag= ldclient.variation(attrs.flag, false);
            if(flag == false){
              element.remove();
            }
          });            
        }
   }
});
arven
  • 1
  • 2
  • what is ldclient ? Can u please add ng-repeat html? – RIYAJ KHAN Oct 12 '16 at 05:32
  • @RIYAJKHAN ldclient is a flagging client module. my ng-repeat html is kinda long thats ehy i havent included it. I tried to use the directive outside of a ng-repeat and its working. but if its inside an ng-repeat its a different story – arven Oct 12 '16 at 05:43

1 Answers1

0

If ldclient is on the scope that ng-repeat is under, then you can add scope: true and use scope.ldclient.on('ready') etc.

Try this:

app.directive('flag', function (utilService) {
    return {
        restrict: 'A',
        scope: true,
        link: function (scope, element, attrs) { 
          scope.ldclient.on('ready', function() {
            var flag = false;         
            console.log(element);
            flag= scope.ldclient.variation(attrs.flag, false);
            if(flag == false){
              element.remove();
            }
          });            
        }
   }
});

This ensures that your directive will share a scope within the DOM that it is placed.

Porlune
  • 740
  • 6
  • 16
  • How about if the ldclient is not on scope? its been declared in a javascript variable that are not part of a scope – arven Oct 12 '16 at 06:38
  • try using console.log(attrs.flag) and see if your value there is being set correctly. Otherwise I don't see why ldclient, if it is present on the window, wouldn't be available within this block. – Porlune Oct 12 '16 at 09:24
  • i logged the attrs.flag and it show the flag that i want.. Its on the ldclient.on event it didnt get.. seems like it can access the ready event that the ldclient emited when he finished its initialization – arven Oct 13 '16 at 03:29
  • could you post a change to your code to reflect where things are working and where they are going wrong? – Porlune Oct 13 '16 at 04:01