Update : Use the following link function:
link: function linkFn(scope,elem,attr){ var jqLiteWrappedElement = angular.element('<input type="url" name="socialUrl" ng-model="social.url">'); elem.replaceWith(jqLiteWrappedElement); $compile(jqLiteWrappedElement)(scope); }
Plunker .
For reasons I donβt understand, replaceWith() must be executed before calling the $ compilation. If someone can explain why this is so, we will be grateful for that!
Update2: in the comments below, Artem mentioned that the DOM needs to be changed before calling the bind function, so this also works:
var myElem = angular.element('some html'); var linkFn = $compile(myElem); element.replaceWith(myElem); linkFn(scope);
Original answer:
Instead of the link function, just use the template in your directive:
template: '<input type="url" name="socialUrl" ng-model="social.url">'
source share