directive factory function

测试指令: 1.工厂函数只执行一次; 2.link函数每个指令实例中都执行。

by creeper ya

HTML

<div ng-app='app'>
    <div test-directive></div>
    <div test-directive></div>
    <div test-directive></div>
</div>

JavaScript

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');
        }
    };
});