1

I have some templates for format text, frecuencia-dia.html or frecuencia-mes.html for example.

I want call a dinamic template using the attributes tipo (text plain) and clave (variable scope).

<ng-formato-texto tipo="frecuencia" clave="{{prod.claveFrecuencia}}" />

app.directive('ngFormatoTexto', function() {
    return {
        templateUrl: function(elem, attr){
            return '/formats/'+attr.tipo+'-'+attr.clave+'.html';
        }
    };
});

But don't work, this try load frecuencia-%7B%7Bprod.clavePrueba%7D%7D.html

1

1 Answer 1

2

You can not use the dynamic template in directive.

As documentation say:

Note: You do not currently have the ability to access scope variables from the templateUrl function, since the template is requested before the scope is initialized.

To create a dynamic directive can use ng-include.

Example:

app.directive('ngFormatoTexto', function() {
 return {
     template: '<div ng-include="path"></div>',
     scope:{
       tipo:"@",
       clave:"="
     },
     link:function(scope){
       scope.path= '/formats/'+scope.tipo+'-'+scope.clave+'.html'
     }
 };
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.