var myModule = angular.module(...); myModule.directive('directiveName', function factory(injectables) { var directiveDefinitionObject = { priority: 0, //指令优先级 template: '<div></div>', //函数(返回值必须是字符串)或者字符串 templateUrl: 'directive.html', //路径 replace: false, //是否替换标签 transclude: false, //是否被模板替换 restrict: 'A', //取值类型,E(元素),A(属性),C(类),M(注释),可以共用如:'EA' scope: false, //作用域 compile: function compile(tElement, tAttrs, transclude) { return { pre: function preLink(scope, iElement, iAttrs, controller) { ... }, post: function postLink(scope, iElement, iAttrs, controller) { ... } } }, link: function postLink(scope, iElement, iAttrs) { ... } }; return directiveDefinitionObject; });