H
H
HAbRAhabp2016-02-22 14:17:57
Angular
HAbRAhabp, 2016-02-22 14:17:57

Why are directives not parsed in ng-bind-html?

Code on JSFIDDLE
For some reason, Angular directives that are taken from a variable do not work. The first tab should show the preluder, but it doesn't. How can you make it work? In theory, the template should be obtained by means of a GET request to the file.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Nemiro, 2016-02-22
@HAbRAhabp

angular-bind-html-compile

(function (angular) {
    'use strict';

    var module = angular.module('angular-bind-html-compile', []);

    module.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);
                });
            }
        };
    }]);
}(window.angular));

Usage:
var app = angular.module('myApp',['ngMaterial', 'ngSanitize', 'angular-bind-html-compile']);
app.controller("My", ['$scope', '$http', function ($scope, $http) {
  $scope.banner = '<md-progress-circular md-diameter="96"></md-progress-circular>'
}]);

bind-html-compile instead of ng-bind-html .
Look

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question