2016-09-22 202 views
0

基于提供给第一个指令的属性,是否可以“指示”指令使用其他特定指令?嵌套指令,其中子指令基于父属性

一个例子:

比方说,我有以下HTML

<parent-directive child-type="foo" /> 

而下面的指令

.directive('parentDirective', function() { 
    return { 
    restrict: 'E', 
    scope: { 
     childType: '@' 
    }, 
    templateUrl: 'parent.html' 
    }; 
}); 

哪里parent.html

<!-- some html --> 
<{{childType}} /> 
<!-- some more html --> 

的d的foo指令

.directive('foo', function() { 
    return { 
    restrict: 'E', 
    scope: { 
    }, 
    templateUrl: 'foo.html' 
    }; 
}); 

以上是不可能的,因为这些指令是在两个阶段中处理,并且childType未链接,直到第二相,链接阶段。有另一种方式,我可以做到这一点?

这里的目标是使用指令来显示一些自定义引导模式,其中模块的页眉和页脚是相同的,但应使用一组不同的指令来插入正文。

感谢

回答

0

好像你想实现某种transclusion的http://teropa.info/blog/2015/06/09/transclusion.html

<parent-directive> 
    <foo></foo> 
</parent-directive> 

.directive('parentDirective', function() { 
    return { 
    restrict: 'E', 
    tranclude: true, 
    templateUrl: 'parent.html' 
    }; 
}); 

parent.html:

<div ng-transclude></div>