title: Calling a rest service only once in angularjs directive
body: <p>We have menu's that can be displayed based on the role. I made the directive for this feature. But the problem is everytime I call the directive its calling rest service. I want to be able to call it only once and save the features that can be accessed for the current role and decide either hide it or show. Below is currently what I have:</p>
  
  <pre><code>var app = angular.module('myApp', []);
  
  app.service('authService', function(){
  
  var user = {};
  user.role = 'guest';
  return{
  getFeature: function(){
    //rest service call
    return featureList;
   },
  
    }
  });
  
  app.directive('restrict', function(authService){
    return{
      restrict: 'A',
      prioriry: 100000,
      scope: false,
      compile:  function(element, attr, linker){
          var accessDenied = true;
          var featureList = authService.getFeature();
          featureList.then(function(result){
            featureList = result;
  
          var attributes = attr.access.split(" ");
          for(var i in featureList){
              if(featureList[i] == attributes[0]){
                  accessDenied = false;
              }
          }
  
  
          if(accessDenied){
              element.children().remove();
              element.remove();           
          }
         });
      }
    }
   });
  </code></pre>
  
  <p>Is there anyway I can call rest service only once not with every directive call?</p>