var app = angular.module('app', []); app.directive('testDirective', function() { alert('Factory function is invoked only once.'); return { template: '<p>Hello world!<br> Test directive factory function invoked only once.</p>', link: function(scope, element, attr) { console.log('execute in every directive'); } }; });
<div ng-app='app'> <div test-directive></div> <div test-directive></div> <div test-directive></div> </div>