我有一个父指令:
.directive("parentDirective", function(){
return{
restrict: "A",
controller: "Ctrl",
scope: {},
transclude: true,
template: "{{output1}}<div ng-transclude></div>",
link: function(scope, elem, attrs){
scope.output1 = "output1"
scope.output2 = "output2"
scope.output3 = "output3"
scope.children = [1,2,3,4]
}
}
})
以下父指令是隔离范围,并且有子指令,我想通过ng-repeat循环:
.directive("childDirective", function(){
return{
restrict: "A",
controller: "Ctrl",
scope: {},
transclude: true,
template: "{{output1}}<div ng-transclude></div>",
link: function(scope, elem, attrs){
scope.output1 = "output1"
scope.output2 = "output2"
scope.output3 = "output3"
}
}
})
HTML:
<body ng-app="app">
<div parent-directive >
{{output2}}
{{children}}
<div child-directive ng-repeat="child in children">
</div>
</div>
</body>
但是由于我已经隔离了范围,因此scope.children = [1,2,3,4]
不会输出到html,然后在孩子的ng-repeat中使用。我该如何解决这个问题?
参见JSBIN:http://jsbin.com/gubamu/2/edit?html,js,output
谢谢!