File tree 2 files changed +53
-1
lines changed
2 files changed +53
-1
lines changed Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ function isBooleanAttribute(node, attrName) {
36
36
function parseIsolateBindings ( scope ) {
37
37
var bindings = { } ;
38
38
_ . forEach ( scope , function ( definition , scopeName ) {
39
- var match = definition . match ( / \s * ( @ | = ( \* ? ) ) \s * ( \w * ) \s * / ) ;
39
+ var match = definition . match ( / \s * ( [ @ & ] | = ( \* ? ) ) \s * ( \w * ) \s * / ) ;
40
40
bindings [ scopeName ] = {
41
41
mode : match [ 1 ] [ 0 ] ,
42
42
collection : match [ 2 ] === '*' ,
@@ -403,6 +403,12 @@ function $CompileProvider($provide) {
403
403
scope . $watch ( parentValueWatch ) ;
404
404
}
405
405
break ;
406
+ case '&' :
407
+ var parentExpr = $parse ( attrs [ attrName ] ) ;
408
+ isolateScope [ scopeName ] = function ( locals ) {
409
+ return parentExpr ( scope , locals ) ;
410
+ } ;
411
+ break ;
406
412
}
407
413
} ) ;
408
414
}
Original file line number Diff line number Diff line change @@ -1392,6 +1392,52 @@ describe('$compile', function() {
1392
1392
} ) ;
1393
1393
} ) ;
1394
1394
1395
+ it ( 'allows binding an invokable expression on the parent scope' , function ( ) {
1396
+ var givenScope ;
1397
+ var injector = makeInjectorWithDirectives ( 'myDirective' , function ( ) {
1398
+ return {
1399
+ scope : {
1400
+ myExpr : '&'
1401
+ } ,
1402
+ link : function ( scope ) {
1403
+ givenScope = scope ;
1404
+ }
1405
+ } ;
1406
+ } ) ;
1407
+ injector . invoke ( function ( $compile , $rootScope ) {
1408
+ $rootScope . parentFunction = function ( ) {
1409
+ return 42 ;
1410
+ } ;
1411
+ var el = $ ( '<div my-directive my-expr="parentFunction() + 1"></div>' ) ;
1412
+ $compile ( el ) ( $rootScope ) ;
1413
+ expect ( givenScope . myExpr ( ) ) . toBe ( 43 ) ;
1414
+ } ) ;
1415
+ } ) ;
1416
+
1417
+ it ( 'allows passing arguments to parent scope expression' , function ( ) {
1418
+ var givenScope ;
1419
+ var injector = makeInjectorWithDirectives ( 'myDirective' , function ( ) {
1420
+ return {
1421
+ scope : {
1422
+ myExpr : '&'
1423
+ } ,
1424
+ link : function ( scope ) {
1425
+ givenScope = scope ;
1426
+ }
1427
+ } ;
1428
+ } ) ;
1429
+ injector . invoke ( function ( $compile , $rootScope ) {
1430
+ var gotArg ;
1431
+ $rootScope . parentFunction = function ( arg ) {
1432
+ gotArg = arg ;
1433
+ } ;
1434
+ var el = $ ( '<div my-directive my-expr="parentFunction(argFromChild)"></div>' ) ;
1435
+ $compile ( el ) ( $rootScope ) ;
1436
+ givenScope . myExpr ( { argFromChild : 42 } ) ;
1437
+ expect ( gotArg ) . toBe ( 42 ) ;
1438
+ } ) ;
1439
+ } ) ;
1440
+
1395
1441
} ) ;
1396
1442
1397
1443
} ) ;
You can’t perform that action at this time.
0 commit comments