1

I have a list named "posts" that comprises of objects like below.

{_id: "559301710de9c23407b237ee"
author: {user_id: "557c6922925a18a81930d2ce", username: "test"}
comment_id: []
content: "<p>123</p>"
created_at: "2015-06-30T20:52:01.738Z"
image_id: []
like_user_id: ["557c6922925a18a81930d2ce"]
likes: 1
tags: [{_id: "558ded1b8526b45407fd0bb1", tag_name: "1"}, {_id: "559301630de9c23407b237ec", tag_name: "2"},…]
title: "123"}

I want to extract tag_name and show it in html

<a ng-repeat="post in bests" ng-href="/post/{{post._id}}">
  <em class="tag">{{post.tags.tag_name}}</em> //This appearently doesn't work!
  <span>{{post.title}}</span>
  <em class="likes">+{{post.likes}}</em>
  <time>{{post.created_at}}</time>
</a>

Everything works fine except for tag_name.

I tried using ng-repeat inside ng-repeat and it doesn't seem to work. how do you do it?

3 Answers 3

3

Try

<em class="tag" ng-repeat="tag in post.tags">{{tag.tag_name}}</em>

post.tags is an array so the easiest way to show the tag_names is using ng-repeat...

Sign up to request clarification or add additional context in comments.

Comments

3

this works

<em class="tag" ng-repeat="tag in post.tags">{{tag.tag_name}}</em>

Comments

3

tags is in an array therefore you need an index in order to use it

{{post.tags[0].tag_name}}

<em class="tag">{{post.tags[0].tag_name}}</em> //<== sample code that works
                            |       

              Your desired index goes here

Alternatively you could iterate using ng-repeat

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.