diff options
| author | Misko Hevery | 2010-03-18 14:43:49 -0700 |
|---|---|---|
| committer | Misko Hevery | 2010-03-18 14:43:49 -0700 |
| commit | df607da0d1b9726bce6584238fe3ad7e9b65a966 (patch) | |
| tree | 472a81182226bde4c3541592f940983c9486eea2 /src | |
| parent | 7634a3ed5227f8bc2a2ba83752d0e2c78adb6051 (diff) | |
| download | angular.js-df607da0d1b9726bce6584238fe3ad7e9b65a966.tar.bz2 | |
support for templates
Diffstat (limited to 'src')
| -rw-r--r-- | src/Scope.js | 15 | ||||
| -rw-r--r-- | src/directives.js | 8 |
2 files changed, 15 insertions, 8 deletions
diff --git a/src/Scope.js b/src/Scope.js index 442477b4..3633f960 100644 --- a/src/Scope.js +++ b/src/Scope.js @@ -1,5 +1,6 @@ function Scope(initialState, name) { this.widgets = []; + this.evals = []; this.watchListeners = {}; this.name = name; initialState = initialState || {}; @@ -11,6 +12,7 @@ function Scope(initialState, name) { this.state['$root'] = this.state; } this.set('$watch', bind(this, this.addWatchListener)); + this.set('$eval', bind(this, this.addEval)); }; Scope.expressionCache = {}; @@ -48,17 +50,23 @@ Scope.prototype = { updateView: function() { var self = this; this.fireWatchers(); - _.each(this.widgets, function(widget){ + foreach(this.widgets, function(widget){ self.evalWidget(widget, "", {}, function(){ this.updateView(self); }); }); + foreach(this.evals, bind(this, this.apply)); }, addWidget: function(controller) { if (controller) this.widgets.push(controller); }, + addEval: function(fn, listener) { + // todo: this should take a function/string and a listener + this.evals.push(fn); + }, + isProperty: function(exp) { for ( var i = 0; i < exp.length; i++) { var ch = exp.charAt(i); @@ -190,8 +198,7 @@ Scope.prototype = { }, fireWatchers: function() { - var self = this; - var fired = false; + var self = this, fired = false; foreach(this.watchListeners, function(watcher) { var value = self.eval(watcher.expression); if (value !== watcher.lastValue) { @@ -206,6 +213,6 @@ Scope.prototype = { }, apply: function(fn) { - fn.apply(this.state, slice(arguments, 0, arguments.length)); + fn.apply(this.state, slice.call(arguments, 1, arguments.length)); } }; diff --git a/src/directives.js b/src/directives.js index 7c5cc257..26cbfe2c 100644 --- a/src/directives.js +++ b/src/directives.js @@ -58,12 +58,12 @@ angular.directive("bind-attr", function(expression, element){ angular.directive("repeat", function(expression, element){ var anchor = document.createComment(expression); jQuery(element).replace(anchor); - var template = this.templetize(element); + var template = this.compile(element); var lhs = "item"; var rhs = "items"; - var children = []; return function(){ - this.$watch(rhs, function(items){ + var children = []; + this.$eval(rhs, function(items){ foreach(children, function(child){ child.element.remove(); }); @@ -102,7 +102,7 @@ angular.directive("action", function(expression, element){ //ng-eval angular.directive("eval", function(expression, element){ return function(){ - this.$onUpdate( expression); + this.$eval(expression); }; }); //ng-watch |
