/** * Template provides directions an how to bind to a given element. * It contains a list of init functions which need to be called to * bind to a new instance of elements. It also provides a list * of child paths which contain child templates */ function Template(priority) { this.paths = []; this.children = []; this.inits = []; this.priority = priority; this.newScope = false; } Template.prototype = { init: function(element, scope) { var inits = {}; this.collectInits(element, inits, scope); forEachSorted(inits, function(queue){ forEach(queue, function(fn) {fn();}); }); }, collectInits: function(element, inits, scope) { var queue = inits[this.priority], childScope = scope; if (!queue) { inits[this.priority] = queue = []; } element = jqLite(element); if (this.newScope) { childScope = createScope(scope); scope.$onEval(childScope.$eval); element.data($$scope, childScope); } forEach(this.inits, function(fn) { queue.push(function() { childScope.$tryEval(function(){ return childScope.$service(fn, childScope, element); }, element); }); }); var i, childNodes = element[0].childNodes, children = this.children, paths = this.paths, length = paths.length; for (i = 0; i < length; i++) { children[i].collectInits(childNodes[paths[i]], inits, childScope); } }, addInit:function(init) { if (init) { this.inits.push(init); } }, addChild: function(index, template) { if (template) { this.paths.push(index); this.children.push(template); } }, empty: function() { return this.inits.length === 0 && this.paths.length === 0; } }; /* * Function walks up the element chain looking for the scope associated with the give element. */ function retrieveScope(element) { var scope; element = jqLite(element); while (element && !(scope = element.data($$scope))) { element = element.parent(); } return scope; } /////////////////////////////////// //Compiler ////////////////////////////////// function Compiler(markup, attrMarkup, directives, widgets){ this.markup = markup; this.attrMarkup = attrMarkup; this.directives = directives; this.widgets = widgets; } Compiler.prototype = { compile: function(rawElement) { rawElement = jqLite(rawElement); var index = 0, template, parent = rawElement.parent(); if (parent && parent[0]) { parent = parent[0]; for(var i = 0; i < parent.childNodes.length; i++) { if (parent.childNodes[i] == rawElement[0]) { index = i; } } } template = this.templatize(rawElement, index, 0) || new Template(); return function(element, parentScope){ element = jqLite(element); var scope = parentScope && parentScope.$eval ? parentScope : createScope(parentScope); element.data($$scope, scope); return extend(scope, { $element:element, $init: function() { template.init(element, scope); scope.$eval(); delete scope.$init; return scope; } }); }; }, /** * @workInProgress * @ngdoc directive * @name angular.directive.ng:eval-order * * @description * Normally the view is updated from top to bottom. This usually is * not a problem, but under some circumstances the values for data * is not available until after the full view is computed. If such * values are needed before they are computed the order of * evaluation can be change using ng:eval-order * * @element ANY * @param {integer|string=} [priority=0] priority integer, or FIRST, LAST constant * * @exampleDescription * try changing the invoice and see that the Total will lag in evaluation * @example
| QTY | Description | Cost | Total | |
| {{item.total = item.qty * item.cost | currency}} | X | |||
| add | {{ items.$sum('total') | currency }} | |||