@@ -793,21 +793,50 @@ function merge(src, dst) {
793793 * @function
794794 *
795795 * @description
796- * Compiles a piece of HTML or DOM into a {@link angular.scope scope} object.
796+ * Compiles a piece of HTML string or DOM into a view and produces a linking function, which can
797+ * then be used to link {@link angular.scope scope} and the template together. The compilation
798+ * process walks the DOM tree and tries to match DOM elements to {@link angular.markup markup},
799+ * {@link angular.attrMarkup attrMarkup}, {@link angular.widget widgets}, and
800+ * {@link angular.directive directives}. For each match it executes coresponding markup, \
801+ * attrMarkup, widget or directive template function and collects the instance functions into a
802+ * single linking function which is then returned. The linking function can then be used
803+ * many-times-over on clones of compiled DOM structure, (For example when compiling
804+ * {@link angular.widget.@ng:repeat repeater} the resulting linking function is called once for
805+ * each item in the collection. The `ng:repeat` does this by cloning the template DOM once for
806+ * each item in collection and then calling the linking function to link the cloned template
807+ * with the a new scope for each item in the collection.)
808+ *
797809 <pre>
798- var scope1 = angular.compile(window.document);
810+ var mvc1 = angular.compile(window.document)();
811+ mvc1.view; // compiled view elment
812+ mvc1.scope; // scope bound to the element
799813
800- var scope2 = angular.compile('<div ng:click="clicked = true">click me</div>');
814+ var mvc2 = angular.compile('<div ng:click="clicked = true">click me</div>')( );
801815 </pre>
802816 *
803- * @param {string|DOMElement } element Element to compile.
804- * @param {Object= } parentScope Scope to become the parent scope of the newly compiled scope.
805- * @returns {Object } Compiled scope object.
817+ * @param {string|DOMElement } element Element or HTML to compile into a template function.
818+ * @returns {function([scope][, element]) } a template function which is used to bind element
819+ * and scope. Where:
820+ *
821+ * * `scope` - {@link angular.scope scope} A scope to bind to. If none specified, then a new
822+ * root scope is created.
823+ * * `element` - {@link angular.element element} Element to use as the template. If none
824+ * specified then reuse the element from `angular.compile(element)`. If `true`
825+ * then clone the `angular.compile(element)`. The element must be either the same
826+ * element as `angular.compile(element)` or an identical clone to
827+ * `angular.compile(element)`. Using an element with differnt structure will cause
828+ * unpredictable behavior.
829+ *
830+ * Calling the template function returns object: `{scope:?, view:?}`, where:
831+ *
832+ * * `view` - the DOM element which represents the compiled template. Either same or clone of
833+ * `element` specifed in compile or template function.
834+ * * `scope` - scope to which the element is bound to. Either a root scope or scope specified
835+ * in the template function.
806836 */
807- function compile ( element , parentScope ) {
808- var compiler = new Compiler ( angularTextMarkup , angularAttrMarkup , angularDirective , angularWidget ) ,
809- $element = jqLite ( element ) ;
810- return compiler . compile ( $element ) ( $element , parentScope ) ;
837+ function compile ( element ) {
838+ return new Compiler ( angularTextMarkup , angularAttrMarkup , angularDirective , angularWidget )
839+ . compile ( element ) ;
811840}
812841/////////////////////////////////////////////////
813842
@@ -989,7 +1018,7 @@ function toKeyValue(obj) {
9891018function angularInit ( config ) {
9901019 if ( config . autobind ) {
9911020 // TODO default to the source of angular.js
992- var scope = compile ( window . document , _null , { '$config' :config } ) ,
1021+ var scope = compile ( window . document ) ( null , createScope ( { '$config' :config } ) ) ,
9931022 $browser = scope . $service ( '$browser' ) ;
9941023
9951024 if ( config . css )
0 commit comments