栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

角度消毒的目的是什么?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

角度消毒的目的是什么?

如果包含

angular-sanitize
脚本,则通过将HTML解析为标记来清理输入。然后将所有安全令牌(来自白名单)序列化回正确转义的html字符串。这意味着没有不安全的输入可以使其进入返回的字符串。

我在下面提供了一个受此博客文章启发的小例子。如果运行此脚本,

var app =angular.module("app", ["ngSanitize"]);
则html链接将正确显示。但是,如果您注释掉该语句并取消注释
var app= angular.module("app", []);
,则会引发以下错误消息:
Error: [$sce:unsafe] Attempting touse an unsafe value in a safe context.

<!DOCTYPE html><html><head>  <link rel="icon" type="image/x-icon" href="favicon.ico">  <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.1/angular.js"></script>  <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.1/angular-sanitize.min.js"></script>  <!-- BEGIN disable refresh -->  <script type="text/javascript">    //Including ngSanitize ensures html links get properly sanitized    var app = angular.module("app", ["ngSanitize"]);    //If you use this pre instead no html links get displayed    //var app = angular.module("app", []);    app.controller("mainController", function($scope) {      var main = this;      main.links = [        "<a href='http://google.com'>Google</a>",        "<a href='http://odetopre.com'>OdeToCode</a>",        "<a href='http://twitter.com'>Twitter</a>"      ];    });  </script></head><body ng-app="app">  <section ng-controller="mainController as main">    <nav>      <ul>        <li ng-repeat="link in main.links" ng-bind-html="link">        </li>      </ul>    </nav>  </section></body></html>


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/636246.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号