This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 2 files changed +11
-3
lines changed
2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -743,7 +743,7 @@ function $RootScopeProvider() {
743
743
while ( asyncQueue . length ) {
744
744
try {
745
745
asyncTask = asyncQueue . shift ( ) ;
746
- asyncTask . scope . $eval ( asyncTask . expression ) ;
746
+ asyncTask . scope . $eval ( asyncTask . expression , asyncTask . locals ) ;
747
747
} catch ( e ) {
748
748
$exceptionHandler ( e ) ;
749
749
}
@@ -958,8 +958,9 @@ function $RootScopeProvider() {
958
958
* - `string`: execute using the rules as defined in {@link guide/expression expression}.
959
959
* - `function(scope)`: execute the function with the current `scope` parameter.
960
960
*
961
+ * @param {(object)= } locals Local variables object, useful for overriding values in scope.
961
962
*/
962
- $evalAsync : function ( expr ) {
963
+ $evalAsync : function ( expr , locals ) {
963
964
// if we are outside of an $digest loop and this is the first time we are scheduling async
964
965
// task also schedule async auto-flush
965
966
if ( ! $rootScope . $$phase && ! asyncQueue . length ) {
@@ -970,7 +971,7 @@ function $RootScopeProvider() {
970
971
} ) ;
971
972
}
972
973
973
- asyncQueue . push ( { scope : this , expression : expr } ) ;
974
+ asyncQueue . push ( { scope : this , expression : expr , locals : locals } ) ;
974
975
} ,
975
976
976
977
$$postDigest : function ( fn ) {
Original file line number Diff line number Diff line change @@ -1243,6 +1243,13 @@ describe('Scope', function() {
1243
1243
expect ( $rootScope . log ) . toBe ( '12' ) ;
1244
1244
} ) ) ;
1245
1245
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
+
1246
1253
it ( 'should run async expressions in their proper context' , inject ( function ( $rootScope ) {
1247
1254
var child = $rootScope . $new ( ) ;
1248
1255
$rootScope . ctx = 'root context' ;
You can’t perform that action at this time.
0 commit comments