Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 7c2d844

Browse files
committed
feat($rootScope): allow passing locals argument to $evalAsync
1 parent 7fd2dc1 commit 7c2d844

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/ng/rootScope.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ function $RootScopeProvider() {
743743
while (asyncQueue.length) {
744744
try {
745745
asyncTask = asyncQueue.shift();
746-
asyncTask.scope.$eval(asyncTask.expression);
746+
asyncTask.scope.$eval(asyncTask.expression, asyncTask.locals);
747747
} catch (e) {
748748
$exceptionHandler(e);
749749
}
@@ -958,8 +958,9 @@ function $RootScopeProvider() {
958958
* - `string`: execute using the rules as defined in {@link guide/expression expression}.
959959
* - `function(scope)`: execute the function with the current `scope` parameter.
960960
*
961+
* @param {(object)=} locals Local variables object, useful for overriding values in scope.
961962
*/
962-
$evalAsync: function(expr) {
963+
$evalAsync: function(expr, locals) {
963964
// if we are outside of an $digest loop and this is the first time we are scheduling async
964965
// task also schedule async auto-flush
965966
if (!$rootScope.$$phase && !asyncQueue.length) {
@@ -970,7 +971,7 @@ function $RootScopeProvider() {
970971
});
971972
}
972973

973-
asyncQueue.push({scope: this, expression: expr});
974+
asyncQueue.push({scope: this, expression: expr, locals: locals});
974975
},
975976

976977
$$postDigest: function(fn) {

test/ng/rootScopeSpec.js

+7
Original file line numberDiff line numberDiff line change
@@ -1243,6 +1243,13 @@ describe('Scope', function() {
12431243
expect($rootScope.log).toBe('12');
12441244
}));
12451245

1246+
it('should allow passing locals to the expression', inject(function($rootScope) {
1247+
$rootScope.log = '';
1248+
$rootScope.$evalAsync('log = log + a', {a: 1});
1249+
$rootScope.$digest();
1250+
expect($rootScope.log).toBe('1');
1251+
}));
1252+
12461253
it('should run async expressions in their proper context', inject(function($rootScope) {
12471254
var child = $rootScope.$new();
12481255
$rootScope.ctx = 'root context';

0 commit comments

Comments
 (0)