Lighthouse Nguyen Lighthouse Nguyen - 10 days ago 5
AngularJS Question

Angularjs directive with dynamic template and transclude

I'm trying add a dynamic template and met problem with transclude.

This is dynamic template function:

var getTemplate = function(contentType){
var template = '<button style="cursor: pointer;">' + contentType + '<ng-transclude></ng-transclude></button>'
return template;
};


And this is code to call the dynamic template:

element.html(getTemplate(attr.firstname));


Look at full code here
https://plnkr.co/edit/cQBeiDkEb8KwhrFWb8iR?p=preview

Please help me to fix it.

This is docs i used: docs

Thank you very much.

Answer

In the plunkr the path to angular script was not found. Changing to <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script> worked

Comments