Answer the question
In order to leave comments, you need to log in
And how to substitute a variable in the directive?
Hello. And how to substitute a variable in the directive? I make a directive that changes its template depending on the incoming value.
If you do so, then
var directive = {
link: link,
templateUrl:
function (element, attrs) {
return attrs.templateUrl ? attrs.templateUrl : '/assets/svg/test.svg';
},
restrict: 'EA',
transclude: true
};
Answer the question
In order to leave comments, you need to log in
the function executes before the compile directive, so the values have not yet been interpolated. What you can do is use the ng-include directive.
return {
template: '<ng-include src="templateUrl"></ng-include>',
scope: {},
link: function (scope, el, attr) {
attr.templateUrl.$observe(); // логика изменения переменной.
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question