【发布时间】:2014-12-13 12:56:20
【问题描述】:
我已经搜索了几个小时,但在使用 ng-repeat 检索时似乎找不到如何解析 HTML 代码。我检查了 $sce.trustAsHtml 但我不知道如何在我的代码中应用它。
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/
谢谢。
【问题讨论】:
标签: html json angularjs ng-repeat