javascript - Angepasste Anweisungen in ng-bind-html werden nicht wirksam!
天蓬老师
天蓬老师 2017-06-16 09:19:14
0
1
882

Problem: Mit ng-bind-html wurde der richtige HTML-Code auf der Seite generiert, aber die Anweisung im Tag wird nicht wirksam!
js-Code:

HTML-Code:

天蓬老师
天蓬老师

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

Antworte allen(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>
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!