日付に基づいてテンプレートを決定する必要があります。良い例を見ました。しかし、その例では、テンプレートが非常に単純であるため、文字列を使用できました。私の場合、php を使用してテンプレートを作成したいので、次のように使用しました。
eng.directive('vis', function ($compile) {
var getTemplate = function(ir) {
var k = (ir.visits.last && parseInt(ir.visits.last.done))?'V':'E';
var s = (ir.data.kind == 0)?'H':'V';
return s+k+'T';
}
var linker = function(scope, element, attrs) {
scope.$watch('ir',function(){
if (!scope.ir) return;
element.html(jQuery('#'+getTemplate(scope.ir)).html()).show();
$compile(element.contents())(scope);
})
}
return {
restrict: "E",
rep1ace: true,
link: linker
};});
テンプレートは次のとおりです。
<div id=HVT style="display:none">
<p>horizontal view template</p>
</div>
<div id=HET style="display:none">
<p>horizontal {{1+5}} Edit template</p>
</div>
<div id=VVT style="display:none">
<p>vertical view template</p>
</div>
<div id=VET style="display:none">
<p>vertical Edit template</p>
</div>
もっとスマートな方法があると確信しています。templateUrl を使用する方が良いですか? 誰かが私の場合にそれを使用する方法を教えてもらえますか?
編集:問題があります。テンプレートはスコープを認識しません