mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-01-12 22:45:52 +08:00
feat($rootScope): allow passing locals argument to $evalAsync
Closes #10390
This commit is contained in:
committed by
Peter Bacon Darwin
parent
c90ad96808
commit
9b96cea462
@@ -742,7 +742,7 @@ function $RootScopeProvider() {
|
||||
while (asyncQueue.length) {
|
||||
try {
|
||||
asyncTask = asyncQueue.shift();
|
||||
asyncTask.scope.$eval(asyncTask.expression);
|
||||
asyncTask.scope.$eval(asyncTask.expression, asyncTask.locals);
|
||||
} catch (e) {
|
||||
$exceptionHandler(e);
|
||||
}
|
||||
@@ -957,8 +957,9 @@ function $RootScopeProvider() {
|
||||
* - `string`: execute using the rules as defined in {@link guide/expression expression}.
|
||||
* - `function(scope)`: execute the function with the current `scope` parameter.
|
||||
*
|
||||
* @param {(object)=} locals Local variables object, useful for overriding values in scope.
|
||||
*/
|
||||
$evalAsync: function(expr) {
|
||||
$evalAsync: function(expr, locals) {
|
||||
// if we are outside of an $digest loop and this is the first time we are scheduling async
|
||||
// task also schedule async auto-flush
|
||||
if (!$rootScope.$$phase && !asyncQueue.length) {
|
||||
@@ -969,7 +970,7 @@ function $RootScopeProvider() {
|
||||
});
|
||||
}
|
||||
|
||||
asyncQueue.push({scope: this, expression: expr});
|
||||
asyncQueue.push({scope: this, expression: expr, locals: locals});
|
||||
},
|
||||
|
||||
$$postDigest: function(fn) {
|
||||
|
||||
@@ -1243,6 +1243,13 @@ describe('Scope', function() {
|
||||
expect($rootScope.log).toBe('12');
|
||||
}));
|
||||
|
||||
it('should allow passing locals to the expression', inject(function($rootScope) {
|
||||
$rootScope.log = '';
|
||||
$rootScope.$evalAsync('log = log + a', {a: 1});
|
||||
$rootScope.$digest();
|
||||
expect($rootScope.log).toBe('1');
|
||||
}));
|
||||
|
||||
it('should run async expressions in their proper context', inject(function($rootScope) {
|
||||
var child = $rootScope.$new();
|
||||
$rootScope.ctx = 'root context';
|
||||
|
||||
Reference in New Issue
Block a user