Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

angularjs

I'm trying to store tab in local storage and fetch that tab in front on refresh page, data got store in local but at the time of feting at console i get error as

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

Here is my angularjs code

$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
    }]
});

and here is my index code

<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>
like image 329
Sachin Sudhakar Sonawane Avatar asked Jan 08 '23 00:01

Sachin Sudhakar Sonawane


1 Answers

Try including angular-sanitize.min.js and inject "ngSanitize" in module declaration in addition to this clear localStorage by calling this "$localStorage.$reset();"

like image 83
nitish.kasar Avatar answered May 13 '23 09:05

nitish.kasar