Asim
Asim

Reputation: 976

Converting ng-repeat table to card

i was woundering how i can convert this type of complex ng-repeat from using table to repeat in AngularJS material design.

My markup looks like this now:

<div class="table-responsive">
                <table class="table">
                    <thead>
                    <tr>
                        <th>AccountName</th>
                        <th>AccountID</th>
                        <th>ContainerID</th>
                        <th>ContainerName</th>
                        <th>Path</th>
                        <th>Favorite</th>
                        <th>Hide</th>
                        <th>Count</th>

                    </tr>
                    </thead>

                    <tbody ng-repeat="(k,v) in containers">
                    <tr ng-repeat="(k1,v1) in v" ng-if="v1.accountId!= null || v1.accountId == ''">
                        <td><a href="{{v1.tagManagerUrl}}">{{ k }}</a></td>
                        <td>{{ v1.accountId }}</td>
                        <td>{{ v1.containerId }}</td>
                        <td>{{ v1.name }}</td>
                        <td><a href="/gui/tags/{{v1.path}}">View Container</a></td>
                    </tr>
                    </tbody>
                </table>

Ive tried using this markup for md-cards but it gets all wrong:

<md-card ng-repeat="(k,v) in containers">
    <md-card-content ng-repeat="(k1,v1) in v">
        <h2 class="md-title">{{ v1.name }}</h2>
        <p>
            {{ v1.accountId }}
        </p>
    </md-card-content>
</md-card>

If you can see the images the request and the ng-repeat it dont look like a table where you have each row for each account/container: enter image description here enter image description here

Upvotes: 0

Views: 1526

Answers (2)

Asim
Asim

Reputation: 976

I got it working with this code:

<div class='md-padding' layout="row" flex>
    <div layout="row" flex>
        <div class="parent" layout="column" ng-repeat="(k,v) in containers">
            <md-card ng-repeat="(k1,v1) in v" ng-if="v1.accountId!= null || v1.accountId == ''">
                <md-card-content>
                    AccountName: {{k}}<br>
                    Accountid: {{ v1.accountId }} <br>
                    ContainerName: {{ v1.name }}
                </md-card-content>
                <div class="md-actions" layout="row" layout-align="end center">
                    <md-button>Save</md-button>
                    <md-button>View</md-button>
                </div>
            </md-card>
        </div>
    </div>
</div>

Upvotes: 0

Zooly
Zooly

Reputation: 4787

If you don't want to repeat the Acccount value, you can do something like this:

<md-card ng-repeat="(k,v) in containers">
    <md-card-content ng-repeat="(k1,v1) in v">
        <h2 class="md-title" ng-if="$first">{{ v1.name }}</h2>
        <p>
            {{ v1.accountId }}
        </p>
    </md-card-content>
</md-card>

Upvotes: 1

Related Questions