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

Commit 9b96cea

Browse files
shahatapetebacondarwin
authored andcommitted
feat($rootScope): allow passing locals argument to $evalAsync
Closes #10390
1 parent c90ad96 commit 9b96cea

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
@@ -742,7 +742,7 @@ function $RootScopeProvider() {
742742
while (asyncQueue.length) {
743743
try {
744744
asyncTask = asyncQueue.shift();
745-
asyncTask.scope.$eval(asyncTask.expression);
745+
asyncTask.scope.$eval(asyncTask.expression, asyncTask.locals);
746746
} catch (e) {
747747
$exceptionHandler(e);
748748
}
@@ -957,8 +957,9 @@ function $RootScopeProvider() {
957957
* - `string`: execute using the rules as defined in {@link guide/expression expression}.
958958
* - `function(scope)`: execute the function with the current `scope` parameter.
959959
*
960+
* @param {(object)=} locals Local variables object, useful for overriding values in scope.
960961
*/
961-
$evalAsync: function(expr) {
962+
$evalAsync: function(expr, locals) {
962963
// if we are outside of an $digest loop and this is the first time we are scheduling async
963964
// task also schedule async auto-flush
964965
if (!$rootScope.$$phase && !asyncQueue.length) {
@@ -969,7 +970,7 @@ function $RootScopeProvider() {
969970
});
970971
}
971972

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

975976
$$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)