This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 2 files changed +15
-3
lines changed
2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -503,12 +503,13 @@ function $RootScopeProvider(){
503
503
* @param {(string|function())= } expression An angular expression to be executed.
504
504
*
505
505
* - `string`: execute using the rules as defined in {@link guide/dev_guide.expressions expression}.
506
- * - `function(scope)`: execute the function with the current `scope` parameter.
506
+ * - `function(scope, locals)`: execute the function with the current `scope` parameter.
507
+ * @param {Object= } locals Hash object of local variables for the expression.
507
508
*
508
509
* @returns {* } The result of evaluating the expression.
509
510
*/
510
- $eval : function ( expr ) {
511
- return $parse ( expr ) ( this ) ;
511
+ $eval : function ( expr , locals ) {
512
+ return $parse ( expr ) ( this , locals ) ;
512
513
} ,
513
514
514
515
/**
Original file line number Diff line number Diff line change @@ -416,8 +416,19 @@ describe('Scope', function() {
416
416
$rootScope . $eval ( function ( self ) { self . b = 2 ; } ) ;
417
417
expect ( $rootScope . b ) . toEqual ( 2 ) ;
418
418
} ) ) ;
419
+
420
+
421
+ it ( 'should allow passing locals to the expression' , inject ( function ( $rootScope ) {
422
+ expect ( $rootScope . $eval ( 'a+1' , { a : 2 } ) ) . toBe ( 3 ) ;
423
+
424
+ $rootScope . $eval ( function ( scope , locals ) {
425
+ scope . c = locals . b + 4 ;
426
+ } , { b : 3 } ) ;
427
+ expect ( $rootScope . c ) . toBe ( 7 ) ;
428
+ } ) ) ;
419
429
} ) ;
420
430
431
+
421
432
describe ( '$evalAsync' , function ( ) {
422
433
423
434
it ( 'should run callback before $watch' , inject ( function ( $rootScope ) {
You can’t perform that action at this time.
0 commit comments