angular js 使用filter 和 directive 是出现错误

新手上路,请多包涵

在动态渲染服务端生成html标签时(标签具有ng-click) 用filter和directive加载到视图时报错:

js代码

filter('htmlContent', ['$sce', function ($sce) {
        return function (text) {
            return $sce.trustAsHtml(text);
        }
    }]
).directive('compileHtml', function ($compile) {
    return {
        restrict: 'A',
        replace: true,
        link: function (scope, ele, attrs) {
            scope.$watch(function () {return scope.$eval(attrs.ngPages);},
                function(html) {
                    ele.html(html);
                    $compile(ele.contents())(scope);
                });
        }
    };
});

html 代码

<div ng-pages="pages|htmlContent" compile-html> </div>

报错代码

图片描述

图片描述

阅读 1.9k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题