$compile
ng
Compiles a piece of HTML string or DOM into a template and produces a template function, which
can then be used to link scope
and the template together.
The compilation is a process of walking the DOM tree and trying to match DOM elements to
directives
. For each match it
executes corresponding template function and collects the
instance functions into a single template function which is then returned.
The template function can then be used once to produce the view or as it is the case with
repeater
many-times, in which
case each call results in a view that is a DOM clone of the original template.
$compile(element, transclude, maxPriority);
Param | Type | Details |
---|---|---|
element | stringDOMElement | Element or HTML string to compile into a template function. |
transclude | function(angular.Scope[, cloneAttachFn] | function available to directives. |
maxPriority | number | only apply directives lower then given priority (Only effects the root element(s), not their children) |
function(scope[, cloneAttachFn]) | a link function which is used to bind template (a DOM element/tree) to a scope. Where:
Calling the linking function returns the element of the template. It is either the original element
passed in, or the clone of the element if the After linking the view is not updated until after a call to $digest which typically is done by Angular automatically. If you need access to the bound view, there are two ways to do it:
For information on how the compiler works, see the Angular HTML Compiler section of the Developer Guide. |