我试图使用<a> tag on an array

时间:2015-10-26 10:07:00

标签: angularjs anchor

<div class="shared-by-list" ng-show="dashpost.showPostSharedByList">
  <span><small><strong><em>Shared by: </em></strong></small></span>
  <span><small>{{dashpost.postSharedByList}}</small></span> 
</div>

In the above code dashpost.postSharedByList is an array of names who shared that particular post. I have to include an <a> tag with href pointing to that specific profile. The problem is the hyperlink is applied to all the names in the array. I want different links for different elements in the array. Please help!

1 个答案:

答案 0 :(得分:0)

<div class="shared-by-list" ng-show="dashpost.showPostSharedByList">
  <div ng-repeat="postSharedBy in dashpost.postSharedByList">
    <span><small><strong><em>Shared by: </em></strong></small></span>
    <span><small><a ng-href="#/profile/{{postSharedBy}}">{{postSharedBy}}</a></small></span> 
  </div>
</div>

如果列表包含如下结构的对象会更好:

{name: "element name", anchorname: "element anchor" }

无论如何,这取决于你的选择。