0

Is it possible to set a string-variable as the content of a template? I'd like to select two different templates depending on the scope. Something like this:

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
        }
    })
});

Is anything like this possible?

1 Answer 1

1

You could use only one template and use ng-switch to load content depending on your scope variable (if you don't mind the extra <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>'
        }
    })
});
Sign up to request clarification or add additional context in comments.

2 Comments

Thx, that worked out very well :) There are a lot of function I still have to get aware of.
Oh, I should say that it's not ng-switch on="temp". It's to be ng-switch="temp" ...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.