2017-04-11 115 views
0

这是我的代码:为什么跨范围与指令范围不同步?

<html ng-app="myApp"> 
<head>    
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.8/angular.js"></script>   
</head> 


<body> 
<div ng-controller="Ctrl"> 
    <testel title="{{data.title}}"> 
     <input ng-model="data.title"> 
     <h3>Transclude title: {{title}}</h3> 
     <h3>Transclude data title: {{data.title}}</h3> 
    </testel> 
</div> 

<script> 

    angular.module('myApp',[]) 
.controller('Ctrl',function($scope){ 
    $scope.data={}; 
    $scope.data.title="Gas"; 
}) 
.directive('testel', function(){ 
    return { 
     restrict: 'E', 
     scope: { 
      title: '@' 
     }, 
     transclude: true, 
     templateUrl: "./transclude.html", 
     link: function(scope, element, attrs, ctrl, transcludeFn) {   
      console.log(scope.$$nextSibling); 
     } 
    }  
}); 
</script>  
</body> 
</html> 

和transclude.html:

<h3>Template title: {{title}}</h3> 
<h3>Template data title:{{data.title}}</h3> 
<ng-transclude></ng-transclude> 

为什么我会收到来自的console.log空($$范围nextSibling)?我正在等待涵盖范围。

另外,我怎么可以console.log的跨境范围本身?

+0

我想这是小孩,不是兄弟 –

+0

绝对是兄弟姐妹! –

回答

0

从Angular 1.3+它是一个孤立范围的孩子。在此之前,他们是兄弟姐妹。