Javascript 如何访问指令的内部指令

Javascript 如何访问指令的内部指令,javascript,angularjs,angularjs-directive,Javascript,Angularjs,Angularjs Directive,我有指令容器和项 指令('container',function()){ 返回{ 替换:正确, 模板:“包含…” } }); 指令('item',函数(){ 返回{ 替换:正确, 模板:“项目” } }); 它们应该这样使用: 预期输出html: 包含项 如何从容器内容中获取项指令,并将其作为可重复指令呈现,以替代容器模板中的…。使用transclude:true选项: directive('container', function(){ return { rep

我有指令
容器

指令('container',function()){ 返回{ 替换:正确, 模板:“包含…

” } }); 指令('item',函数(){ 返回{ 替换:正确, 模板:“项目” } }); 它们应该这样使用:


预期输出html:

包含项


如何从
容器
内容中获取
指令,并将其作为可重复指令呈现,以替代容器模板中的

使用
transclude:true
选项:

directive('container', function(){
    return {
        replace: true,
        transclude: true,
        template: "<div>contains <p ng-transculde></p> </div>'
    }
});
指令('container',function()){ 返回{ 替换:正确, 是的, 模板:“包含

” } });
由于指令模板必须只有一个html根元素,
模板:“项”
无效。它必须至少类似于
模板:'item'
,它产生:

<div>
    contains 
    <p>
        <span>item</span>
        <span>item</span>
        <span>item</span>
    </p>
</div>

包含

项目
项目
项目

这两项指示是:

app.directive('container', function() {
  return {
    restrict: 'E',
    replace: true,
    transclude: true,
    template: '<div>contains <p ng-transclude></p></div>'
  };
});

app.directive('item', function() {
  return {
    restrict: 'E',
    replace: true,
    template: '<span>item</span>'
  };
});
app.directive('container',function(){
返回{
限制:'E',
替换:正确,
是的,
模板:“包含

” }; }); app.directive('item',function(){ 返回{ 限制:'E', 替换:正确, 模板:“项目” }; });

只需谷歌“AngularJS指令转换”@Blackhole我知道转换是解决问题的正确方法,但找不到好的例子。最好的例子通常是。