簡體   English   中英

Angular - 帶動態模板的指令

[英]Angular - Directive with dynamic template

我用動態模板創建了一個指令,它運行良好。 問題是我收到一個錯誤:

在Chrome = TypeError:undefined不是forEach.attr的函數
在Firefox = Error:element.setAttribute不是函數

這是代碼:

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

指令標簽:

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

經過長時間的運行我找到了解決方案,問題是:

replace:true,

刪除此部分后問題得以解決。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM