@@ -901,7 +901,7 @@ function $CompileProvider($provide) {
901
901
return linkFnFound ? compositeLinkFn : null ;
902
902
903
903
function compositeLinkFn ( scope , nodeList , $rootElement , boundTranscludeFn ) {
904
- var nodeLinkFn , childLinkFn , node , childScope , childTranscludeFn , i , ii , n ;
904
+ var nodeLinkFn , childLinkFn , node , $node , childScope , childTranscludeFn , i , ii , n ;
905
905
906
906
// copy nodeList so that linking doesn't break due to live list updates.
907
907
var stableNodeList = [ ] ;
@@ -913,11 +913,13 @@ function $CompileProvider($provide) {
913
913
node = stableNodeList [ n ] ;
914
914
nodeLinkFn = linkFns [ i ++ ] ;
915
915
childLinkFn = linkFns [ i ++ ] ;
916
+ $node = jqLite ( node ) ;
916
917
917
918
if ( nodeLinkFn ) {
918
919
if ( nodeLinkFn . scope ) {
919
- childScope = scope . $new ( isObject ( nodeLinkFn . scope ) ) ;
920
- jqLite ( node ) . data ( '$scope' , childScope ) ;
920
+ childScope = scope . $new ( ) ;
921
+ $node . data ( '$scope' , childScope ) ;
922
+ safeAddClass ( $node , 'ng-scope' ) ;
921
923
} else {
922
924
childScope = scope ;
923
925
}
@@ -1155,10 +1157,8 @@ function $CompileProvider($provide) {
1155
1157
assertNoDuplicate ( 'new/isolated scope' , newIsolateScopeDirective , directive ,
1156
1158
$compileNode ) ;
1157
1159
if ( isObject ( directiveValue ) ) {
1158
- safeAddClass ( $compileNode , 'ng-isolate-scope' ) ;
1159
1160
newIsolateScopeDirective = directive ;
1160
1161
}
1161
- safeAddClass ( $compileNode , 'ng-scope' ) ;
1162
1162
}
1163
1163
}
1164
1164
@@ -1291,7 +1291,7 @@ function $CompileProvider($provide) {
1291
1291
1292
1292
}
1293
1293
1294
- nodeLinkFn . scope = newScopeDirective && newScopeDirective . scope ;
1294
+ nodeLinkFn . scope = newScopeDirective && newScopeDirective . scope === true ;
1295
1295
nodeLinkFn . transclude = transcludeDirective && childTranscludeFn ;
1296
1296
1297
1297
// might be normal or delayed nodeLinkFn depending on if templateUrl is present
@@ -1303,11 +1303,13 @@ function $CompileProvider($provide) {
1303
1303
if ( pre ) {
1304
1304
if ( attrStart ) pre = groupElementsLinkFnWrapper ( pre , attrStart , attrEnd ) ;
1305
1305
pre . require = directive . require ;
1306
+ if ( newIsolateScopeDirective === directive ) pre . isolateScope = true ;
1306
1307
preLinkFns . push ( pre ) ;
1307
1308
}
1308
1309
if ( post ) {
1309
1310
if ( attrStart ) post = groupElementsLinkFnWrapper ( post , attrStart , attrEnd ) ;
1310
1311
post . require = directive . require ;
1312
+ if ( newIsolateScopeDirective === directive ) post . isolateScope = true ;
1311
1313
postLinkFns . push ( post ) ;
1312
1314
}
1313
1315
}
@@ -1348,7 +1350,7 @@ function $CompileProvider($provide) {
1348
1350
1349
1351
1350
1352
function nodeLinkFn ( childLinkFn , scope , linkNode , $rootElement , boundTranscludeFn ) {
1351
- var attrs , $element , i , ii , linkFn , controller ;
1353
+ var attrs , $element , i , ii , linkFn , controller , isolateScope ;
1352
1354
1353
1355
if ( compileNode === linkNode ) {
1354
1356
attrs = templateAttrs ;
@@ -1359,8 +1361,11 @@ function $CompileProvider($provide) {
1359
1361
1360
1362
if ( newIsolateScopeDirective ) {
1361
1363
var LOCAL_REGEXP = / ^ \s * ( [ @ = & ] ) ( \? ? ) \s * ( \w * ) \s * $ / ;
1364
+ var $linkNode = jqLite ( linkNode ) ;
1362
1365
1363
- var parentScope = scope . $parent || scope ;
1366
+ isolateScope = scope . $new ( true ) ;
1367
+ $linkNode . data ( '$isolateScope' , isolateScope ) ;
1368
+ safeAddClass ( $linkNode , 'ng-isolate-scope' ) ;
1364
1369
1365
1370
forEach ( newIsolateScopeDirective . scope , function ( definition , scopeName ) {
1366
1371
var match = definition . match ( LOCAL_REGEXP ) || [ ] ,
@@ -1370,19 +1375,19 @@ function $CompileProvider($provide) {
1370
1375
lastValue ,
1371
1376
parentGet , parentSet ;
1372
1377
1373
- scope . $$isolateBindings [ scopeName ] = mode + attrName ;
1378
+ isolateScope . $$isolateBindings [ scopeName ] = mode + attrName ;
1374
1379
1375
1380
switch ( mode ) {
1376
1381
1377
1382
case '@' :
1378
1383
attrs . $observe ( attrName , function ( value ) {
1379
- scope [ scopeName ] = value ;
1384
+ isolateScope [ scopeName ] = value ;
1380
1385
} ) ;
1381
- attrs . $$observers [ attrName ] . $$scope = parentScope ;
1386
+ attrs . $$observers [ attrName ] . $$scope = scope ;
1382
1387
if ( attrs [ attrName ] ) {
1383
1388
// If the attribute has been provided then we trigger an interpolation to ensure
1384
1389
// the value is there for use in the link fn
1385
- scope [ scopeName ] = $interpolate ( attrs [ attrName ] ) ( parentScope ) ;
1390
+ isolateScope [ scopeName ] = $interpolate ( attrs [ attrName ] ) ( scope ) ;
1386
1391
}
1387
1392
break ;
1388
1393
@@ -1393,23 +1398,23 @@ function $CompileProvider($provide) {
1393
1398
parentGet = $parse ( attrs [ attrName ] ) ;
1394
1399
parentSet = parentGet . assign || function ( ) {
1395
1400
// reset the change, or we will throw this exception on every $digest
1396
- lastValue = scope [ scopeName ] = parentGet ( parentScope ) ;
1401
+ lastValue = isolateScope [ scopeName ] = parentGet ( scope ) ;
1397
1402
throw $compileMinErr ( 'nonassign' ,
1398
1403
"Expression '{0}' used with directive '{1}' is non-assignable!" ,
1399
1404
attrs [ attrName ] , newIsolateScopeDirective . name ) ;
1400
1405
} ;
1401
- lastValue = scope [ scopeName ] = parentGet ( parentScope ) ;
1402
- scope . $watch ( function parentValueWatch ( ) {
1403
- var parentValue = parentGet ( parentScope ) ;
1406
+ lastValue = isolateScope [ scopeName ] = parentGet ( scope ) ;
1407
+ isolateScope . $watch ( function parentValueWatch ( ) {
1408
+ var parentValue = parentGet ( scope ) ;
1404
1409
1405
- if ( parentValue !== scope [ scopeName ] ) {
1410
+ if ( parentValue !== isolateScope [ scopeName ] ) {
1406
1411
// we are out of sync and need to copy
1407
1412
if ( parentValue !== lastValue ) {
1408
1413
// parent changed and it has precedence
1409
- lastValue = scope [ scopeName ] = parentValue ;
1414
+ lastValue = isolateScope [ scopeName ] = parentValue ;
1410
1415
} else {
1411
1416
// if the parent can be assigned then do so
1412
- parentSet ( parentScope , parentValue = lastValue = scope [ scopeName ] ) ;
1417
+ parentSet ( scope , parentValue = lastValue = isolateScope [ scopeName ] ) ;
1413
1418
}
1414
1419
}
1415
1420
return parentValue ;
@@ -1418,8 +1423,8 @@ function $CompileProvider($provide) {
1418
1423
1419
1424
case '&' :
1420
1425
parentGet = $parse ( attrs [ attrName ] ) ;
1421
- scope [ scopeName ] = function ( locals ) {
1422
- return parentGet ( parentScope , locals ) ;
1426
+ isolateScope [ scopeName ] = function ( locals ) {
1427
+ return parentGet ( scope , locals ) ;
1423
1428
} ;
1424
1429
break ;
1425
1430
@@ -1435,7 +1440,7 @@ function $CompileProvider($provide) {
1435
1440
if ( controllerDirectives ) {
1436
1441
forEach ( controllerDirectives , function ( directive ) {
1437
1442
var locals = {
1438
- $scope : scope ,
1443
+ $scope : directive === newIsolateScopeDirective ? isolateScope : scope ,
1439
1444
$element : $element ,
1440
1445
$attrs : attrs ,
1441
1446
$transclude : boundTranscludeFn
@@ -1467,21 +1472,22 @@ function $CompileProvider($provide) {
1467
1472
for ( i = 0 , ii = preLinkFns . length ; i < ii ; i ++ ) {
1468
1473
try {
1469
1474
linkFn = preLinkFns [ i ] ;
1470
- linkFn ( scope , $element , attrs ,
1475
+ linkFn ( linkFn . isolateScope ? isolateScope : scope , $element , attrs ,
1471
1476
linkFn . require && getControllers ( linkFn . require , $element ) ) ;
1472
1477
} catch ( e ) {
1473
1478
$exceptionHandler ( e , startingTag ( $element ) ) ;
1474
1479
}
1475
1480
}
1476
1481
1477
1482
// RECURSION
1478
- childLinkFn && childLinkFn ( scope , linkNode . childNodes , undefined , boundTranscludeFn ) ;
1483
+ // TODO(vojta): only pass isolate if the isolate directive has template
1484
+ childLinkFn && childLinkFn ( isolateScope || scope , linkNode . childNodes , undefined , boundTranscludeFn ) ;
1479
1485
1480
1486
// POSTLINKING
1481
1487
for ( i = postLinkFns . length - 1 ; i >= 0 ; i -- ) {
1482
1488
try {
1483
1489
linkFn = postLinkFns [ i ] ;
1484
- linkFn ( scope , $element , attrs ,
1490
+ linkFn ( linkFn . isolateScope ? isolateScope : scope , $element , attrs ,
1485
1491
linkFn . require && getControllers ( linkFn . require , $element ) ) ;
1486
1492
} catch ( e ) {
1487
1493
$exceptionHandler ( e , startingTag ( $element ) ) ;
0 commit comments