首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ngSanitize不使用angularJs?

ngSanitize不使用angularJs?
EN

Stack Overflow用户
提问于 2017-02-06 14:59:21
回答 1查看 371关注 0票数 0

我有模态窗口,我有来自父控制器的数据,我在模态中也有搜索功能,但是当我打开模态时,它没有将数据呈现到模态视图中,而是在控制台中看到对象打印,但它没有绑定到html。我在下面粘贴了错误,知道这里实现了什么错误吗?

searchModal.html

代码语言:javascript
复制
<div class="row search-input-margin">
    <div class="col-md-12 form-group">
        <div class="col-md-3">
            <label for="search">Search Logs:</label>
        </div>
        <div class="col-md-9">
            <input type="text" class="form-control" id="search" ng-model="vm.searchLog">
        </div>
    </div>
</div>
<div class="modal-body">
    <div class="row">
        <ul class="searchLogsText">
         <li  ng-repeat="item in data  | filter:vm.searchLog track by $index" ng-bind-html="item | highlight:vm.searchLog"></li>
        </ul>
    </div>
</div>

searcCtrl.js

代码语言:javascript
复制
angular.module('loggingApp').controller('SearchController',function ($scope,$rootScope,$uibModalInstance,searchFactory) {
    'use strict';
    $scope.cancel = function() {
        $uibModalInstance.close();
    }
    $scope.vm ={
        searchLog:'',
        searchLength:0,
        searchResults: []

    };
    $scope.data = angular.copy(searchFactory.getDitLogs());
    console.log(searchFactory.getDitLogs());
});

错误:

错误:$sce:itype试图在需要字符串的内容中信任非字符串值:

EN

回答 1

Stack Overflow用户

发布于 2017-02-06 18:13:50

您需要将ngSanitize作为依赖项添加,并且当您想要使用字符串作为html时,应该调用$sce.trustAsHtml函数。

代码语言:javascript
复制
  var myApp = angular.module('myApp',['ngSanitize']);

  myApp.controller('myCtrl', ['$sce', '$scope' , function($sce, $scope) {
      var html = '<div>Hello Html!</div>'; 
      $scope.editorHtml = $sce.trustAsHtml(html);

    }]);

请查看此小提琴或查看我的aswser 这里

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42070806

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档