Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/388.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用angularJs时ngSanitize不起作用?_Javascript_Angularjs_Twitter Bootstrap - Fatal编程技术网

Javascript 使用angularJs时ngSanitize不起作用?

Javascript 使用angularJs时ngSanitize不起作用?,javascript,angularjs,twitter-bootstrap,Javascript,Angularjs,Twitter Bootstrap,我有一个模态窗口,其中有来自父控制器的数据,我在模态中也有搜索功能,但当我打开模态时,它没有将数据呈现到模态视图中,我看到对象在控制台中打印,但它没有绑定到html。 我在下面粘贴了错误,你知道这里的错误是什么吗 searchModal.html <div class="row search-input-margin"> <div class="col-md-12 form-group"> <div class="col-md-3">

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

searchModal.html

<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>
错误:

错误:[$sce:itype]试图信任需要字符串:上下文:html的内容中的非字符串值

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

  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);

    }]);
var myApp=angular.module('myApp',['ngSanitize']);
myApp.controller('myCtrl',['$sce','$scope',函数($sce,$scope){
var html='Hello html!';
$scope.editorHtml=$sce.trustAsHtml(html);
}]);

检查此项或查看my aswser查看更多详细信息看起来您的
项不是字符串(/html),而是对象。因此,您的
searchFactory.getDitLogs()
可能会返回一个对象数组。也许你的意思是“searchFactory.getDitLogs”函数的代码会很有帮助,创建一个简单的示例说明这个函数返回什么?它只是getter和setter工厂,所以我正在从父级设置数据并进入模式。控制台正在打印数据。看起来您没有将ngSanitize添加为依赖项。。。angular.module('loggingApp',['ngSanitize'])…ngSanitize已添加我没有将app.js添加到问题中,但it依赖性在那里$sce依赖性不需要,也不需要使用TrustAshTML如何才能做到?你能这样做吗?你说“是”是什么意思!我的脚本不工作了!!!运行两个示例以查看不同的。
  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);

    }]);