You can access the $ scope directive from the Link function, $ compile any HTML and add it to the directive element (which could actually be initialized as empty):
angular.module("example")
.directive('example', function($compile) {
return {
restrict: 'E',
link: function(scope, element, attrs){
scope.nums = [1, 2, 3];
var html = '<div ng-model="scope"><p ng-repeat="n in nums">{{ n }}</p></div>';
var el = $compile(html)(scope);
element.append(el);
}
}
});
Note that I must explicitly specify the data model for the tag (ng-model = "scope"). I could not get it to work differently.
source
share