Angular - Dynamic Template Directive

I created a directive with a dynamic template and it works well. The problem is I am getting the error:

In Chrome = TypeError: undefined is not a function for forEach.attr
In Firefox = Error: element.setAttribute is not a function

Here is the code:

return {
    restrict:'E',
    replace:true,
    scope:{
        content:'@'
    },
    controller:function($scope){
        $scope.getTemplateUrl = function() {
            if($scope.content.match(/<img/i) && !$scope.content.match(/icon-subs/i)) {
                return 'app/templates/_image.html';
            } else if ($scope.content.match(/<a/i)) {
                return 'app/templates/_link.html';
            } else if ($scope.content.match(/<iframe/i)) {
                return 'app/templates/_video.html';
            } else {
                return 'app/templates/_minutes.html';
            }
        }
    },
    template: '<div ng-include="getTemplateUrl()"></div>'
};

      

Directive tag:

<div ng-repeat="lance in contentsArray">
    <icone-timeline data-content="{{lance.content}}"></icone-timeline>
    <div ng-bind-html="lance.content"></div>
</div>

      

+3


source to share


1 answer


After running for a long time, I found a solution, the problem was:

replace:true,

      



After removing this part, the problem was resolved.

-1


source







All Articles