加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 错误:[$sce:unsafe]试图在安全的上下文中使用不

发布时间:2020-12-17 17:53:42 所属栏目:安全 来源:网络整理
导读:我正在尝试将标签存储在本地存储中并在刷新页面前面获取该标签,数据存储在本地,但在控制台上进行竞争时我得到错误 Error: [$sce:unsafe] Attempting to use an unsafe value in a safe context. 这是我的angularjs代码 $scope.data=$localStorage.$default({
我正在尝试将标签存储在本地存储中并在刷新页面前面获取该标签,数据存储在本地,但在控制台上进行竞争时我得到错误

Error: [$sce:unsafe] Attempting to use an unsafe value in a safe
context.

这是我的angularjs代码

$scope.data=$localStorage.$default({
    tab: [{   
        name:'Default 1',page: $sce.trustAsHtml('<tab class="portlet" id="internalTabs">first internal</tab>'),image: $sce.trustAsHtml('<img style="float : right; " src = "'+token_url+'images/grp1_setting_icon.png" >'),Width: 100
    }]
});

这是我的索引代码

<tabset>
              <tab class="grp_left"
                   ng-model='newTab'
                   sortable-tab
                   ng-repeat="tab in data.tab" 
                   index='{{$index}}' 
                   style='width: {{tab.Width}}%;'
                   id='{{$index}}'
                >
                <tab-heading>
                      {{tab.name}}   <span popover-template="dynamicPopover.templateUrl" popover-placement="bottom" rel="popover"><i ng-bind-html="tab.image"></i></span>

                </tab-heading>
                <!-- below is template of popover for add delete and rename tabs-->
                <script type="text/ng-template" id="myPopoverTemplate.html">
                  <div class="form-group">
                    <label>Enter Title : </label> <span ng-click='closePopup($event)' id='closePopup' ><i class="fa fa-times" style='float:right;'>close</i></span>
                     <input type="text" maxlength="12" focus-me='true' ng-model="tab.name" class="form-control ">
                    <button class='btn-warning btn-xl'ng-click='RenameTab($event,tab.name)' style='margin-top:6px;' ><span class="glyphicon glyphicon-ok" ></span>Add</button>
                    <button class='btn-danger btn-xl' ng-click='removeTab($event,$index)' style='margin-top:6px;' ><span  class="glyphicon glyphicon-remove" ></span>Delete</button>
                   </div>
                </script><!-- end of template code   -->
                <span ng-bind-html="tab.page" ></span>
              </tab>
            </tabset>

解决方法

尝试包括angular-sanitize.min.js 并通过调用“$localStorage.$reset();”在模块声明中注入“ngSanitize”以及此明确的localStorage.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读