javascript - Arahan tersuai dalam ng-bind-html tidak berkuat kuasa!
天蓬老师
天蓬老师 2017-06-16 09:19:14
0
1
881

Masalah: Menggunakan ng-bind-html, kod html yang betul telah dijana pada halaman, tetapi arahan dalam teg tidak berkuat kuasa!
js kod:

kod html:

天蓬老师
天蓬老师

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

membalas semua(1)
刘奇

Sudah tentu ia tidak akan berkesan, ng-bind-html 等同于 innerHTML.

Anda boleh menyesuaikan arahan yang serupa dengan 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>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan
Tentang kita Penafian Sitemap
Laman web PHP Cina:Latihan PHP dalam talian kebajikan awam,Bantu pelajar PHP berkembang dengan cepat!