Thank you for your attention.
I'm intermediate in my Angular know-how and I'm trying to make a dynamic directive/widget.
I've got massive headache from my neck being out and I'm trying to fix this on my own, but I need someone to point me in the right direction.
I have a directive:
(function () {
'use strict';
angular.module('app')
.directive('tool', function() {
return {
restrict: 'E',
templateUrl: 'tool-template.html'
}
})
;
})();
tool-template.html:
<div class="tool-wrap">
<svg>
</svg>
</div>
I'm adding the directive to the view dynamically, using the main controller:
(function(){
'use strict';
angular.module('app')
.controller('MainController', function(UserModel, Auth, $state, $window, $compile, $scope){
var ctrl = this;
var project = $(.project);
// ...
ctrl.btnDown = function (event) {
switch(event.which) {
case 1:
project.append(add());
break;
default:
break;
}
};
var add = function () {
return $compile("<tool></tool>")($scope);
};
// ...
})
;
});
From what I've gathered I need to use '$compile' to add the new directive element to the dom dynamically. Is this correct?
The issue I'm having is.. I'm able to add the new HTML element tool-tags, but when I open the browser developer toolbar (shift + ctrl + J), the contents of tool-template isn't inside the tool-tags. i.e. The div and svg.
I understand the answer must be painfully obvious but, I'm struggling and I want to get this work done today.