I have an interesting situation, which I fully admit I may not be handling correctly.
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:
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 < 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');
});
});
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:
dirInfo1: {
Name: directiveOne,
templateUrl: /html/directiveOne.html,
controller: controllerOne
}
dirInfo2: {
Name: directiveTwo,
templateUrl: /html/directiveTwo.html,
controller: controllerTwo
}
In this case, only directiveTwo.html is shown, and only controllerTwo fires.
Any help would be greatly appreciated.