【发布时间】:2017-02-06 14:59:21
【问题描述】:
我有模态窗口,其中有来自父控制器的数据我也有模态搜索功能,但是当我打开模态时,它不会将数据呈现到模态视图中,我在控制台中看到对象打印,但它没有绑定到 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>
searcCtrl.js
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] 试图信任需要字符串的内容中的非字符串值:上下文:html
【问题讨论】:
-
看起来您的
item不是字符串 (/html),而是一个对象。所以你的searchFactory.getDitLogs()可能会返回一个对象数组。也许你的意思是ng-bind-html="item.someHtmlProperty" -
“searchFactory.getDitLogs”函数的代码会有所帮助,创建一个简单的示例来说明该函数返回什么?
-
它只是 getter 和 setter 工厂,所以我从父级设置数据并进入模态。控制台正在打印数据
-
看起来您没有将 ngSanitize 添加为依赖项... angular.module('loggingApp', ['ngSanitize']) ...
-
ngSanitize 添加了我没有添加 app.js 来质疑,但它的依赖是存在的
标签: javascript angularjs twitter-bootstrap