javascript - Customized instructions in ng-bind-html do not take effect!
天蓬老师
天蓬老师 2017-06-16 09:19:14
0
1
905

Problem: Using ng-bind-html, the correct html code has been generated on the page, but the directive in the tag does not take effect!
js code:

html code:

天蓬老师
天蓬老师

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

reply all(1)
刘奇

Of course it will not take effect, ng-bind-html is equivalent to innerHTML.

You can customize a command similar to 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>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template