2014-08-27 15 views
1

非常感謝這個問題,這個問題是當我使用transclude指令時,角度子範圍沒有從父範圍繼承,這個問題與angular.js版本有關係,在1.2.17之前可以工作發佈版本1.2 .18之後無效爲什麼angular.js transclude child child不會繼承parentScope?

這些是實際測試結果的兩個版本。 http://jsfiddle.net/a3ywb2c4/

var App= angular.module("myApp",[]); 
App.controller("testCtrl",function($scope){ 
$scope.names= [{name:"janry",value:123},{name:"janry",value:123},{name:"janry",value:123}] 
$scope.dd="hello world" 

});

App.directive("testDire",function($parse){ 
return { 
    restrict:'A', 
    transclude:true, 
    template:"<div ng-repeat='$item in $items' ng-transclude></div>", 
    scope:false, 
    link:function(scope,iele,attrs,ctrl,transclude){ 
     var getter=$parse(attrs.data) 
     scope.$items = getter(scope);  
    } 
}; 

})

http://jsfiddle.net/m3fo9om3/

回答

2

這是AngularJS是如何構建的:爲transcluded指令範圍是容器指令的兄弟,他們都繼承父範圍。

This post有很好的解釋和解決辦法。