SORU
2 Temmuz 2013, Salı


açısal ng-bind-html-güvensiz ve Yönerge içinde

Plunker Link

Bunun için html bağlamak istediğim bir unsur var.

<div ng-bind-html-unsafe="details" upper></div>

O çalışır. Şimdi, onunla birlikte ben de bağlı html bağlı bir Direktif var:

$scope.details = 'Success! <a href="#/details/12" upper>details</a>'

Ama div ile Direktif upper ve çapa değerlendirin. Nasıl başaracağım?

CEVAP
2 Temmuz 2013, Salı


Ayrıca bu sorun ile karşı karşıya kaldım ve saat internet arama yaptıktan sonra @çözüm olduğunu kanıtladı Chandermani yorum okudum. Bir araman lazım 'derleme' bu model ile: Yönerge

HTML:

<div compile="details"></div>

JS:

.directive('compile', ['$compile', function ($compile) {
    return function(scope, element, attrs) {
        scope.$watch(
            function(scope) {
                // watch the 'compile' expression for changes
                return scope.$eval(attrs.compile);
            },
            function(value) {
                // when the 'compile' expression changes
                // assign it into the current DOM
                element.html(value);

                // compile the new DOM and link it to the current
                // scope.
                // NOTE: we only compile .childNodes so that
                // we don't get into infinite loop compiling ourselves
                $compile(element.contents())(scope);
            }
        );
    };
}])

Bir çalışma fiddle of it here görebilirsiniz

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • FrankJavCee

    FrankJavCee

    29 Kasım 2008
  • RealPapaPit

    RealPapaPit

    16 Mart 2009
  • Trulia

    Trulia

    29 Kasım 2006