0

テンプレートのコンテンツとして文字列変数を設定することは可能ですか? スコープに応じて 2 つの異なるテンプレートを選択したいと考えています。このようなもの:

define(['app'], function(app){
    app.directive('logstorelist', function(){
        var temp="";
        return{
            scope: true,
            restrict: 'A',
            link: function(s, e, a){
                if(a=="a")
                    temp = "<a>tempA</a>";
                else
                    temp = "<div>temp</div>";
            },
            replace: true,
            template: temp
        }
    })
});

このようなことは可能ですか?

4

1 に答える 1

1

スコープ変数に応じて、テンプレートを 1 つだけ使用ng-switchしてコンテンツを読み込むことができます (余分な を気にしない場合<span>)。

define(['app'], function(app){
    app.directive('logstorelist', function(){
        var temp="";
        return{
            scope: true,
            restrict: 'A',
            link: function(s, e, a){
                s.temp = a;
            },
            replace: true,
            template: 
            ' <span ng-switch="temp">
                <a ng-switch-when="a">tempA</a>
                <div ng-switch-default>temp</div>
            </span>'
        }
    })
});
于 2013-09-30T11:28:18.370 に答える