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 @@ -742,7 +742,7 @@ function $RootScopeProvider() {
742
742
while ( asyncQueue . length ) {
743
743
try {
744
744
asyncTask = asyncQueue . shift ( ) ;
745
- asyncTask . scope . $eval ( asyncTask . expression ) ;
745
+ asyncTask . scope . $eval ( asyncTask . expression , asyncTask . locals ) ;
746
746
} catch ( e ) {
747
747
$exceptionHandler ( e ) ;
748
748
}
@@ -957,8 +957,9 @@ function $RootScopeProvider() {
957
957
* - `string`: execute using the rules as defined in {@link guide/expression expression}.
958
958
* - `function(scope)`: execute the function with the current `scope` parameter.
959
959
*
960
+ * @param {(object)= } locals Local variables object, useful for overriding values in scope.
960
961
*/
961
- $evalAsync : function ( expr ) {
962
+ $evalAsync : function ( expr , locals ) {
962
963
// if we are outside of an $digest loop and this is the first time we are scheduling async
963
964
// task also schedule async auto-flush
964
965
if ( ! $rootScope . $$phase && ! asyncQueue . length ) {
@@ -969,7 +970,7 @@ function $RootScopeProvider() {
969
970
} ) ;
970
971
}
971
972
972
- asyncQueue . push ( { scope : this , expression : expr } ) ;
973
+ asyncQueue . push ( { scope : this , expression : expr , locals : locals } ) ;
973
974
} ,
974
975
975
976
$$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