aboutsummaryrefslogtreecommitdiffstats
path: root/src/service
diff options
context:
space:
mode:
Diffstat (limited to 'src/service')
-rw-r--r--src/service/formFactory.js2
-rw-r--r--src/service/scope.js16
2 files changed, 11 insertions, 7 deletions
diff --git a/src/service/formFactory.js b/src/service/formFactory.js
index 565b22a4..5d64131e 100644
--- a/src/service/formFactory.js
+++ b/src/service/formFactory.js
@@ -377,7 +377,7 @@ function $FormFactoryProvider() {
// Set the state to something we know will change to get the process going.
widget.$modelValue = Number.NaN;
// watch for scope changes and update the view appropriately
- modelScope.$watch(scopeGet, function(scope, value) {
+ modelScope.$watch(scopeGet, function(value) {
if (!equals(widget.$modelValue, value)) {
widget.$modelValue = value;
widget.$parseModel ? widget.$parseModel() : (widget.$viewValue = value);
diff --git a/src/service/scope.js b/src/service/scope.js
index 089e4a41..f59417bc 100644
--- a/src/service/scope.js
+++ b/src/service/scope.js
@@ -207,7 +207,7 @@ function $RootScopeProvider(){
scope.counter = 0;
expect(scope.counter).toEqual(0);
- scope.$watch('name', function(scope, newValue, oldValue) { counter = counter + 1; });
+ scope.$watch('name', function(newValue, oldValue) { counter = counter + 1; });
expect(scope.counter).toEqual(0);
scope.$digest();
@@ -231,22 +231,26 @@ function $RootScopeProvider(){
* the `watchExpression` changes.
*
* - `string`: Evaluated as {@link guide/dev_guide.expressions expression}
- * - `function(scope, newValue, oldValue)`: called with current `scope` an previous and
- * current values as parameters.
+ * - `function(newValue, oldValue, scope)`: called with current and previous values as parameters.
* @returns {function()} Returns a deregistration function for this listener.
*/
$watch: function(watchExp, listener) {
var scope = this,
get = compileToFn(watchExp, 'watch'),
- listenFn = compileToFn(listener || noop, 'listener'),
array = scope.$$watchers,
watcher = {
- fn: listenFn,
+ fn: listener,
last: initWatchVal,
get: get,
exp: watchExp
};
+ // in the case user pass string, we need to compile it, do we really need this ?
+ if (!isFunction(listener)) {
+ var listenFn = compileToFn(listener || noop, 'listener');
+ watcher.fn = function(newVal, oldVal, scope) {listenFn(scope);};
+ }
+
if (!array) {
array = scope.$$watchers = [];
}
@@ -341,7 +345,7 @@ function $RootScopeProvider(){
if ((value = watch.get(current)) !== (last = watch.last) && !equals(value, last)) {
dirty = true;
watch.last = copy(value);
- watch.fn(current, value, ((last === initWatchVal) ? value : last));
+ watch.fn(value, ((last === initWatchVal) ? value : last), current);
if (ttl < 5) {
logIdx = 4 - ttl;
if (!watchLog[logIdx]) watchLog[logIdx] = [];