<tfoot id='YORgQ'></tfoot>

      1. <small id='YORgQ'></small><noframes id='YORgQ'>

        <legend id='YORgQ'><style id='YORgQ'><dir id='YORgQ'><q id='YORgQ'></q></dir></style></legend>
        <i id='YORgQ'><tr id='YORgQ'><dt id='YORgQ'><q id='YORgQ'><span id='YORgQ'><b id='YORgQ'><form id='YORgQ'><ins id='YORgQ'></ins><ul id='YORgQ'></ul><sub id='YORgQ'></sub></form><legend id='YORgQ'></legend><bdo id='YORgQ'><pre id='YORgQ'><center id='YORgQ'></center></pre></bdo></b><th id='YORgQ'></th></span></q></dt></tr></i><div id='YORgQ'><tfoot id='YORgQ'></tfoot><dl id='YORgQ'><fieldset id='YORgQ'></fieldset></dl></div>
          <bdo id='YORgQ'></bdo><ul id='YORgQ'></ul>

        angularJS 如何忽略某些 HTML 标签?

        angularJS How can I ignore certain HTML tags?(angularJS 如何忽略某些 HTML 标签?)

        <small id='nAZU1'></small><noframes id='nAZU1'>

        • <legend id='nAZU1'><style id='nAZU1'><dir id='nAZU1'><q id='nAZU1'></q></dir></style></legend>

            <bdo id='nAZU1'></bdo><ul id='nAZU1'></ul>
                <i id='nAZU1'><tr id='nAZU1'><dt id='nAZU1'><q id='nAZU1'><span id='nAZU1'><b id='nAZU1'><form id='nAZU1'><ins id='nAZU1'></ins><ul id='nAZU1'></ul><sub id='nAZU1'></sub></form><legend id='nAZU1'></legend><bdo id='nAZU1'><pre id='nAZU1'><center id='nAZU1'></center></pre></bdo></b><th id='nAZU1'></th></span></q></dt></tr></i><div id='nAZU1'><tfoot id='nAZU1'></tfoot><dl id='nAZU1'><fieldset id='nAZU1'></fieldset></dl></div>

                <tfoot id='nAZU1'></tfoot>
                    <tbody id='nAZU1'></tbody>
                  本文介绍了angularJS 如何忽略某些 HTML 标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我收到此错误是因为其中一位用户在他的帖子中添加了 <3

                  I got this error because one of the users added in his post <3

                  错误:[$sanitize:badparse] sanitizer 无法解析以下 html 块:<3

                  Error: [$sanitize:badparse] The sanitizer was unable to parse the following block of html: <3

                  我写的代码 ng-bind-html ="Detail.details"

                  我要他只取<a>标签和<br/>

                  这可能吗?

                  谢谢!

                  推荐答案

                  您可以创建过滤器来清理您的 html.

                  You can create filter which will sanitize your html.

                  我在其中使用了 strip_tags 函数http://phpjs.org/functions/strip_tags/

                  I used in it strip_tags function http://phpjs.org/functions/strip_tags/

                  angular.module('filters', []).factory('truncate', function () {
                      return function strip_tags(input, allowed) {
                        allowed = (((allowed || '') + '')
                          .toLowerCase()
                          .match(/<[a-z][a-z0-9]*>/g) || [])
                          .join(''); // making sure the allowed arg is a string containing only tags in lowercase (<a><b><c>)
                        var tags = /</?([a-z][a-z0-9]*)[^>]*>/gi,
                          commentsAndPhpTags = /<!--[sS]*?-->|<?(?:php)?[sS]*??>/gi;
                        return input.replace(commentsAndPhpTags, '')
                          .replace(tags, function($0, $1) {
                            return allowed.indexOf('<' + $1.toLowerCase() + '>') > -1 ? $0 : '';
                          });
                      }
                  });
                  

                  控制器:

                  angular.module('myApp', ['filters'])
                  .controller('IndexController', ['$scope', 'truncate', '$sce', function($scope, truncate, $sce){
                    $scope.text="";
                  
                    $scope.$watch('text', function(){
                      $scope.sanitized = $sce.trustAsHtml(truncate($scope.text, '<a><br>'));
                    });
                  }]);
                  

                  查看:

                  <div ng-bind-html="sanitized"></div>
                  

                  http://plnkr.co/edit/qOuvpSMvooC6jR0HxCNT?p=preview

                  这篇关于angularJS 如何忽略某些 HTML 标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  quot;Status Code:200 OK (from ServiceWorker)quot; in Chrome Network DevTools?(“状态码:200 OK(来自 ServiceWorker)在 Chrome 网络开发工具中?)
                  What is quot;X-Content-Type-Options=nosniffquot;?(什么是“X-Content-Type-Options=nosniff?)
                  SmtpJs API not working! is there any way to send emails using SMTP server with JavaScript or JQuery(SmtpJs API 不工作!有没有办法使用带有 JavaScript 或 JQuery 的 SMTP 服务器发送电子邮件)
                  Can I send email using javascript(我可以使用 javascript 发送电子邮件吗)
                  Select All the objects on canvas using Fabric.js(使用 Fabric.js 选择画布上的所有对象)
                  Crop the image using JavaScript(使用 JavaScript 裁剪图像)

                  <small id='5dScw'></small><noframes id='5dScw'>

                  • <i id='5dScw'><tr id='5dScw'><dt id='5dScw'><q id='5dScw'><span id='5dScw'><b id='5dScw'><form id='5dScw'><ins id='5dScw'></ins><ul id='5dScw'></ul><sub id='5dScw'></sub></form><legend id='5dScw'></legend><bdo id='5dScw'><pre id='5dScw'><center id='5dScw'></center></pre></bdo></b><th id='5dScw'></th></span></q></dt></tr></i><div id='5dScw'><tfoot id='5dScw'></tfoot><dl id='5dScw'><fieldset id='5dScw'></fieldset></dl></div>

                          <tbody id='5dScw'></tbody>
                        <tfoot id='5dScw'></tfoot>

                        <legend id='5dScw'><style id='5dScw'><dir id='5dScw'><q id='5dScw'></q></dir></style></legend>
                        • <bdo id='5dScw'></bdo><ul id='5dScw'></ul>