aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Angular.js6
-rw-r--r--src/Compiler.js20
-rw-r--r--src/widgets.js19
3 files changed, 18 insertions, 27 deletions
diff --git a/src/Angular.js b/src/Angular.js
index f9047d32..5bd5e547 100644
--- a/src/Angular.js
+++ b/src/Angular.js
@@ -800,10 +800,8 @@ function merge(src, dst) {
* Compiles a piece of HTML or DOM into a {@link angular.scope scope} object.
<pre>
var scope1 = angular.compile(window.document);
- scope1.$init();
var scope2 = angular.compile('<div ng:click="clicked = true">click me</div>');
- scope2.$init();
</pre>
*
* @param {string|DOMElement} element Element to compile.
@@ -948,7 +946,7 @@ function toKeyValue(obj) {
(function(window, previousOnLoad){
window.onload = function(){
try { (previousOnLoad||angular.noop)(); } catch(e) {}
- angular.compile(window.document).$init();
+ angular.compile(window.document);
};
})(window, window.onload);
&lt;/script&gt;
@@ -1002,8 +1000,6 @@ function angularInit(config){
$browser.addCss(config.base_url + config.css);
else if(msie<8)
$browser.addJs(config.base_url + config.ie_compat, config.ie_compat_id);
-
- scope.$init();
}
}
diff --git a/src/Compiler.js b/src/Compiler.js
index 804a9622..6aee40b8 100644
--- a/src/Compiler.js
+++ b/src/Compiler.js
@@ -13,7 +13,7 @@ function Template(priority) {
}
Template.prototype = {
- init: function(element, scope) {
+ attach: function(element, scope) {
var inits = {};
this.collectInits(element, inits, scope);
forEachSorted(inits, function(queue){
@@ -96,18 +96,14 @@ Compiler.prototype = {
template = this.templatize(element, index, 0) || new Template();
return function(element, parentScope){
element = jqLite(element);
- var scope = parentScope && parentScope.$eval ?
- parentScope : createScope(parentScope);
+ 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;
- }
- });
+ template.attach(element, scope);
+ scope.$element = element;
+ scope.$eval();
+ return scope;
};
},
diff --git a/src/widgets.js b/src/widgets.js
index 7438254d..66c9ecc5 100644
--- a/src/widgets.js
+++ b/src/widgets.js
@@ -677,7 +677,6 @@ angularWidget('ng:include', function(element){
element.html(response);
childScope = useScope || createScope(scope);
compiler.compile(element)(element, childScope);
- childScope.$init();
scope.$eval(onloadExp);
});
} else {
@@ -795,7 +794,6 @@ var ngSwitch = angularWidget('ng:switch', function (element){
element.append(caseElement);
childScope.$tryEval(switchCase.change, element);
switchCase.template(caseElement, childScope);
- childScope.$init();
}
});
});
@@ -891,7 +889,7 @@ angularWidget('a', function() {
angularWidget("@ng:repeat", function(expression, element){
element.removeAttr('ng:repeat');
element.replaceWith(jqLite("<!-- ng:repeat: " + expression + " --!>"));
- var template = this.compile(element);
+ var linker = this.compile(element);
return function(reference){
var match = expression.match(/^\s*(.+)\s+in\s+(.*)\s*$/),
lhs, rhs, valueIdent, keyIdent;
@@ -912,6 +910,7 @@ angularWidget("@ng:repeat", function(expression, element){
var children = [], currentScope = this;
this.$onEval(function(){
var index = 0,
+ cloneElement,
childCount = children.length,
lastElement = reference,
collection = this.$tryEval(rhs, reference),
@@ -937,16 +936,17 @@ angularWidget("@ng:repeat", function(expression, element){
if (keyIdent) childScope[keyIdent] = key;
} else {
// grow children
- childScope = template(quickClone(element), createScope(currentScope));
+ childScope = createScope(currentScope);
childScope[valueIdent] = collection[key];
if (keyIdent) childScope[keyIdent] = key;
- lastElement.after(childScope.$element);
childScope.$index = index;
childScope.$position = index == 0 ?
- 'first' :
- (index == collectionLength - 1 ? 'last' : 'middle');
- childScope.$element.attr('ng:repeat-index', index);
- childScope.$init();
+ 'first' :
+ (index == collectionLength - 1 ? 'last' : 'middle');
+ cloneElement = quickClone(element);
+ lastElement.after(cloneElement);
+ cloneElement.attr('ng:repeat-index', index);
+ linker(cloneElement, childScope);
children.push(childScope);
}
childScope.$eval();
@@ -1069,7 +1069,6 @@ angularWidget('ng:view', function(element) {
$xhr('GET', src, function(code, response){
element.html(response);
compiler.compile(element)(element, childScope);
- childScope.$init();
});
} else {
element.html('');