title: How can I add new directive information from a database?
body: <p>I have an interesting situation, which I fully admit I may not be handling correctly.</p>
  
  <p>I want to load directives in to an Angular app using AngularAMD, but the information on the directives is coming from a database/API call. Here's how I'm handing it at the moment:</p>
  
  <pre><code>app.run(function ($rootScope, $state, $http) {
      $rootScope.$state = $state;
      $rootScope.rootPages = JSON.parse(localStorage.pages);
  
      $http.get('api/Directives').then(function (resp) {
          for (var i = 0; i &lt; resp.data.length; i++) {
              var dirInfo = resp.data[i];
              var dirConfig = JSON.parse(dirInfo.Configuration);
  
              angularAMD.directive(dirInfo.Name, function () {
                  return {
                      restrict: 'E',
                      controller: eval(dirConfig.controller),
                      templateUrl: dirConfig.templateUrl,
                      scope: true,
                  }
              });
          }
      }, function (error) {
          alert('error');
      });
  });
  </code></pre>
  
  <p>At the moment this generates two directives, and I have two links on my page, one for each module (using angular-ui-router and router-ui-extras to load those based on another database table/API call). Theoretically clicking link 1 should bring up directive 1, and link 2 should bring up directive 2. However, when I click link 1, directive 2 comes up. It's almost as if the only directive that registers is directive 2.
  Here's the information I get from the database:</p>
  
  <pre><code>dirInfo1: {
      Name: directiveOne,
      templateUrl: /html/directiveOne.html,
      controller: controllerOne
  }
  
  dirInfo2: {
      Name: directiveTwo,
      templateUrl: /html/directiveTwo.html,
      controller: controllerTwo
  }    
  </code></pre>
  
  <p>In this case, only directiveTwo.html is shown, and only controllerTwo fires.</p>
  
  <p>Any help would be greatly appreciated.</p>