我一直在寻找几个小时,我似乎无法找到使用ng-repeat进行检索时如何解析HTML代码。我检出了$ sce.trustAsHtml,但我不知道如何将其应用于我的代码中。在ng-repeat中解析html
HTML文件:
<div ng-app="myApp">
<div ng-controller="MyCtrl">
<h2>My Links</h2>
<table class="table table-bordered">
<thead>
<tr>
<td>Name</td>
<td>URL</td>
</tr>
</thead>
<tbody>
<tr ng-repeat="stuff in myStuff()">
<td>{{stuff.name}}</td>
<td>{{stuff.url}}</td>
</tr>
</tbody>
</table>
</div>
的JavaScript
var myApp = angular.module('myApp', []);
myApp.controller('MyCtrl', function ($scope) {
$scope.myStuff = function() {
return [
{
'name':'Google',
'url':'<a href="http://google.com">Google</a>'
},
{
'name':'Yahoo',
'url':'<a href="http://yahoo.com">Yahoo</a>'
},
{
'name':'Microsoft',
'url':'<a href="http://microsoft.com">Microsoft</a>'
}
];
};
});
它显示HTML源代码,但我希望它编译代码。我的JS方法错了吗?一旦我明白了这一点,我将使用$ http指令将它应用于json文件。任何人都可以点亮一下吗?我的代码是http://jsfiddle.net/s2ykvy8n/
谢谢。
忘了这个!好东西。 – dannypaz 2014-10-17 21:37:01
@PSL就是这样!我之前尝试ngSanitize,但没有奏效。现在我知道为什么。我认为angular.min.js是完整的。事实证明它没有angular-sanitize.js。现在,我也包括这一点,它的作品。谢谢 – w1n78 2014-10-17 21:44:25
@ w1n78 yup !!,不客气.. :) – PSL 2014-10-17 22:27:19