angular.module('vkApp', []);
angular.module('vkApp')
.controller('vkController', ['$scope', '$compile', function ($scope, $compile) {
var data = {
article : '<vk></vk>'
}
$scope.data = data;
}]);
angular.module('vkApp')
.directive('vk', ['$compile', function ($compile) {
return {
template: '<div>Content of vk</div>',
restrict: 'E',
link: function(scope, element, attrs){
console.log('"link" function inside directive vk called, "element" param is: ', element)
}
};
}]);
// declare a new module, and inject the $compileProvider
angular.module('vkApp')
.directive('compile', ['$compile', function ($compile) {
return function(scope, element, attrs) {
var ensureCompileRunsOnce = scope.$watch(
function(scope) {
// watch the 'compile' expression for changes
return scope.$eval(attrs.compile);
},
function(value) {
// when the 'compile' expression changes
// assign it into the current DOM
element.html(value);
// compile the new DOM and link it to the current
// scope.
// NOTE: we only compile .childNodes so that
// we don't get into infinite loop compiling ourselves
$compile(element.contents())(scope);
// Use Angular's un-watch feature to ensure compilation only happens once.
ensureCompileRunsOnce();
}
);
};
}]);
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.