File tree Expand file tree Collapse file tree 2 files changed +11
-3
lines changed
Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Original file line number Diff line number Diff 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 ) {
Original file line number Diff line number Diff 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' ;
You can’t perform that action at this time.
0 commit comments