javascript - ng-bind-html中 自訂的指令 不生效!
天蓬老师
天蓬老师 2017-06-16 09:19:14
0
1
851

問題:使用ng-bind-html 頁面上已經產生了正確的html程式碼,但是標籤中的 指令 不生效!
js程式碼:

#html程式碼:

#
天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

全部回覆(1)
刘奇

當然無法生效,ng-bind-html 等同於 innerHTML

可以自訂一個類似 ng-bind-html-compile 的指令:

.directive('bindHtmlCompile', ['$compile', function ($compile) {
        return {
            restrict: 'A',
            link: function (scope, element, attrs) {
                scope.$watch(function () {
                    return scope.$eval(attrs.bindHtmlCompile);
                }, function (value) {
                    // In case value is a TrustedValueHolderType, sometimes it
                    // needs to be explicitly called into a string in order to
                    // get the HTML string.
                    element.html(value && value.toString());
                    // If scope is provided use it, otherwise use parent scope
                    var compileScope = scope;
                    if (attrs.bindHtmlScope) {
                        compileScope = scope.$eval(attrs.bindHtmlScope);
                    }
                    $compile(element.contents())(compileScope);
                });
            }
        };
    }]);
<p ng-bind-html-compile="getId(xxx)"></p>
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!