【问题标题】:Error: [$sce:unsafe] Attempting to use an unsafe value in a safe context错误:[$sce:unsafe] 尝试在安全上下文中使用不安全值
【发布时间】:2015-07-07 07:01:54
【问题描述】:

我正在尝试将选项卡存储在本地存储中,并在刷新页面上获取前面的选项卡,数据存储在本地,但在控制台上显示时出现错误

错误:[$sce:unsafe] 试图在保险箱中使用不安全的值 上下文。

这是我的 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>

【问题讨论】:

标签: angularjs


【解决方案1】:

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

【讨论】:

  • 我也包含了 angular-sanitize.min.js 但仍然面临同样的问题
  • 试试 $localStorage.$reset();一开始
  • 我用过它,但在删除标签时。谢谢它对我有用,因为我把“$localStorage.$reset();”放在了开始
猜你喜欢
  • 1970-01-01
  • 2017-06-19
  • 2014-11-15
  • 1970-01-01
  • 2019-03-01
  • 2013-04-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多