I am trying to load -outside angular - dynamically a custom directive
but the custom directive is not loaded in spite I have used $compile
as the following :
the custom directive is :
app.directive('mydirective',function (){
return {
template: '<div>Succeeded !</div>',
}
})
and here the place I am loading dynamically the directive :
function showresultcust() {
angular.injector(['ng']).invoke(['$compile',
function ($compile) {
var scope = angular.element(document.getElementById("test1")).scope();
var _html = '<div>{{name}}-</div><div mydirective >Not Succeed</div>';
//var _html='<div >{{loaded}}</div>';
var obj = $('#content');
$('#content').html($compile(_html)(scope));
// compile!!!
$compile(obj.contents())(scope);
scope.$digest();
setTimeout(function () {
scope.$apply();
});
}
]);
}
Please note that {{name}}
in the dynamic HTML is loaded correctly, but not the custom directive.
The full demo is in this 'plnkr.co' link
If you could do the correction directly in the 'plnkr' link above, I would appreciate that.