Ответы пользователя по тегу Angular
  • Как убрать экранирование с помощью angular?

    AlekseyNemiro
    @AlekseyNemiro
    full-stack developer
    Поиск и замена?
    return $sce.trustAsHtml(text.replace(/\\/g, ''));
    Можно отдельный фильтр для этого сделать :-)

    Набросал пример, у меня слеш и так не выводится:

    <div ng-app="app">
      <div ng-controller="ExampleController">
        <p ng-bind-html="text | trusted"></p>
      </div>
    </div>

    angular.module('app', []).controller('ExampleController', function($scope) {
      $scope.text = "A GREAT LOT, THIS IS THE ONE YOU\'VE BEEN LOOKING FOR";
    }).filter('trusted', ['$sce', function ($sce) {
      return function (text) {
        return $sce.trustAsHtml(text); // $sce.trustAsHtml(text.replace(/\\/g, ''));
      };
    }]);
    Ответ написан
    Комментировать
  • Почему не парсятся директивы в ng-bind-html?

    AlekseyNemiro
    @AlekseyNemiro
    full-stack developer
    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));

    Использование:
    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 вместо ng-bind-html.

    Посмотреть
    Ответ написан
    Комментировать