2

I'm having trouble displaying my location object. I'm displaying it but it's throwing the whole array and I'm kind of stuck at this part.

My problem is how to remove the [] bracket.

enter image description here

location json

[
{
    "_id": "5a61acfdd5df1761dd2eb1ef",
    "branch": "Lucena City",
    "__v": 0,
    "building": [
        {
            "name": "mhq",
            "floors": [
                "1st",
                "2nd",
                "3rd"
            ]
        }
    ],
    "dateCreated": "2018-01-19T08:31:57.121Z"
}

]

HTML

<table class="table table-sm">
<thead>
    <tr>
        <th>Branch</th>
        <th>Building</th>
        <th>Floors</th>
    </tr>
</thead>
<tbody>
    <tr ng-repeat="loc in vm.locations">
        <td>{{ loc.branch }}</td>
        <td>{{ loc.building[0].name }}</td>
        <td>
            {{ loc.building[0].floors }}
        </td>
    </tr>
</tbody>
</table>

3 Answers 3

1

You could use Array#join()

 {{ loc.building[0].floors.join(', ') }}
Sign up to request clarification or add additional context in comments.

Comments

1

You just need to call the join function

loc.building[0].floors.join(",");

Hope it helps!

Comments

1

The answers above are right.

You can also create a filter say to_csv_string that takes an array and returns a comma separated string, then you can pipe the result as

{{ loc.building[0].floors| to_csv_string }}. Now you could reuse it wherever its required

I have a demo plunker, you can have a look if you like.

https://plnkr.co/edit/yFJXEiIW3fmL4A7L7kt7?p=preview

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.