1Angular.module (' ModuleName ', []). Directive (2' Namespacedirectivename ',3[function() {4 return {5Restrict: ",//describes how directives are used in templates, including element e, attributes a,css style classes, annotations, or any of the above6priority:0,//sets the order in which directives are executed in the template, in order relative to other directives7Template: ",//writes an inline template as a string, which is ignored if the template is provided as a URL8Templateurl: ",//describes the URLs required to load the template. This property is ignored if the template is provided in temlate form9Replace:true,//if set to True, replace the element that contains the directive, or append it to the inside of the elementTenTransclude:true,//move the original child node of the instruction element into a new template interior OneScope: ' bool or object ',//creates a new scope for the current instruction, rather than inheriting it from the parent scope AConstroller:function($scope, $element, $attrs, $transclude) { - //Create a controller that exposes an API that can communicate between multiple instructions using this API - }, theRequire: ",//requires that another instruction must exist for the current instruction to execute -Link:function(Scope, ielement, iattrs) { - //programmatically modifies an instance of the resulting DOM element, adds an event listener, and sets the data binding - }, +Compile:function(TElement, Tattrs, transclude) { - //you can use Ng-repeat to programmatically modify the DOM template to implement an instruction that spans multiple instructions. + //You can also return a link function, which you can use to modify an example of the resulting element A return { atPre:functionprelink (Scope, ielement, Iattrs, - Controller) { - }, -Post:functionPostlink (Scope, ielement, Iattrs, - Controller) { - } in - } to } + }; -} ]);
Writing instruction templates in Angularjs