angularjs - 错误 : [$sce:unsafe] Attempting to use an unsafe value in a safe context

标签 angularjs

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

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();”在模块声明中注入(inject)“ngSanitize”,除了这个明确的localStorage

关于angularjs - 错误 : [$sce:unsafe] Attempting to use an unsafe value in a safe context,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31261855/

相关文章:

javascript - 在指令和 Controller 之间使用公共(public)作用域

php - Smarty PHP 与 AngularJS 冲突

javascript - ui 路由器中的 Angular Provider 访问

javascript - 我可以在 Angular 的 Promise 链中调用函数吗

javascript - AngularJS Promise Chaining 中返回相同的数据

javascript - 不评估模板内的变量

javascript - AngularJS - 在一个简单的应用程序上获取 "Uncaught Error: [$injector:modulerr]"消息

javascript - 单选按钮不会对 ng-change 指令使用react

javascript - 在没有 $scope 的情况下使用 $watch( Controller 作为语法)

javascript - Angular JS 中的 For Each 循环