2016-09-22 2 views
0

ディレクティブが最初のディレクティブに指定された属性に基づいて別のディレクティブを使用するように "指示"することはできますか?子ディレクティブが親属性に基づいているネストされたディレクティブ

例:

はのは、私は、次のHTML

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

そして、次のディレクティブを持っているとしましょうparent.html

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

ある

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

ディレクティブは二相で処理され、そしてchildTypeは、第二相、リンクフェーズまで連結されていないため、D foo指令

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

上記は、不可能です。私はこれを行うことができる別の方法はありますか?

ここでの目標は、カスタムブートストラップモーダルを表示するためにディレクティブを使用することです。ここでは、モーダルのヘッダーとフッターは同じですが、本文は異なるディレクティブのセットを使用して挿入する必要があります。

おかげ

答えて

0

あなたはトランスクルー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> 
関連する問題