Angularjs 如何在另一个自定义指令中重复和呈现自定义指令的数组?

Angularjs 如何在另一个自定义指令中重复和呈现自定义指令的数组?,angularjs,custom-directive,Angularjs,Custom Directive,我有三个自定义指令child1、child2、child3,我想在ng repeat中使用另一个自定义指令从contoller重复。在控制器中获取数组,创建一个父自定义指令,并将每个数组元素传递给父指令,然后在父指令中仅使用$compile编译并附加到DOM 控制器: 父指令: 其他三项指令: HTML: 你能添加更多的上下文吗?还有更多代码?没有代码没有帮助 $scope.directiveArray=['child1','child2','child3']; angular.module(

我有三个自定义指令child1、child2、child3,我想在ng repeat中使用另一个自定义指令从contoller重复。

在控制器中获取数组,创建一个父自定义指令,并将每个数组元素传递给父指令,然后在父指令中仅使用$compile编译并附加到DOM

控制器:

父指令:

其他三项指令:

HTML:


你能添加更多的上下文吗?还有更多代码?没有代码没有帮助
$scope.directiveArray=['child1','child2','child3'];
angular.module('myApp').directive('parentDirective',function($compile){
   return {
            restrict:'AE',
            replace:true,
            link:function(scope,element,attribute){<br>
            var html=$compile("<"+attribute.childelem+"></"+attribute.childelem+">")(scope);
            element.append(html);
         }
       }
    });
angular.module('myApp').directive('child1',function(){
  return {
           restrict:'AE',
           template:'<h1>this is Child 1'
         }
    });

angular.module('myApp').directive('child2',function(){
  return {
           restrict:'AE',
           template:'<h1>this is Child 2'
         }
    });
angular.module('myApp').directive('child3',function(){
  return {
           restrict:'AE',
           template:'<h1>this is Child 3'
         }
       });
<div ng-repeat="elem in directiveArray">
    <parent-directive childelem="{{elem}}"><parent-directive>
</div>