在我的案例中,href不能使用ng-repeat

时间:2014-05-25 06:18:13

标签: javascript angularjs

演示:http://plnkr.co/edit/ktnDiUSA7eU7DNkIbTqo

   <ul>
       <li ng-repeat="thread in data">
           <a href="{{thead.url}}" target="_blank">
                {{thread.title}}
           </a>
       </li>
   </ul>

我得到了这样的json

$scope.data = [
{
    "title": " 'Aku kecewa, tiada harapan kalahkan DAP'",
    "desc": "BACKER QUITS ?",
    "starter": "rhoyo",
    "replies": " 23 ",
    "url": "https://forum.lowyat.net/Kopitiam/topic/3235530"
},
{
    "title": " Angry China launches war against terror ",
    "desc": "",
    "starter": "rivost",
    "replies": " 6 ",
    "url": "https://forum.lowyat.net/Kopitiam/topic/3235746"
}

];

为什么当我{{thread.url}}确实打印出直接网址?

2 个答案:

答案 0 :(得分:0)

您需要使用Angular ng Href指令。只需将href替换为ng-href

看看这里:https://docs.angularjs.org/api/ng/directive/ngHref

答案 1 :(得分:0)

首先,你应该修正拼写错误thread.url而不是thead.url

然后将href属性替换为ng-href

<a ng-href="{{thread.url}}" target="_blank">
    {{thread.title}}
</a>