i'm working on a formbuilder and would like to be able to dynamically create instances of my directives at runtime.
I've got all of the functionality working, except the rendering. I can render an instance through $compile, but when i try adding some internal functionality in the directive, it does not resolve the binding ?
My Directive
.directive('formElType', function ($compile) {
var txt_label = 'Please type your text here';
return {
restrict: 'E',
replace: true,
scope: {
txt_label: '=',
},
template: '<div class="fbuild-playground-el-wrap" ng-click="openSettings($event)">' +
'<div class="fbuild-playground-el">' +
'<p>{{ txt_label }}</p>' +
'</div>' +
'</div>',
link: function (scope, elem, attrs) {
scope.txt_label = txt_label;
$compile(elem.contents())(scope);
}
};
});
Javascript Code that renders the directive
$scope.componentDrop = function(e) {
angular.element(
$compile('<form-el-type></form-el-type>')()
).appendTo($scope.comp_dropzone);
};