SD Dev
SD Dev

Reputation: 345

Displaying a blank ng-repeat on purpose (for a nested array)

I'm iterating (ng-repeat) over a childArray of an existing loop with ng-repeat, but I want blank results to show on my child ng-repeat. Is there any way to do that? I have an element structure I want to be shown from the child ng-repeat.

The code looks like this :

<ng-repeat="row in parentArray"> <--- the parent array
{{row.name}}
{{row.date}}
{{row.place}}

    <ng-repeat="option in row"> <--- the child array
    Result : {{option.name}} <-- I still want result to show up

</ng-repeat>
</ng-repeat>

Upvotes: 0

Views: 138

Answers (1)

Tobias Timm
Tobias Timm

Reputation: 2050

If i understand you correctly, you wanna show something if there is no option?

ng-repeat only works with data. When there is no data, nothing is displayed. For this purpose you can use ng-if or ng-show / ng-hide

Also it is very unclear for me at the moment, where the options are stored in the row

HTML

<ng-repeat="row in parentArray"> <--- the parent array
{{row.name}}
{{row.date}}
{{row.place}}


    <div ng-if="row.options.length > 0">
        <ng-repeat="option in row.options"> <--- the child array
        Result : {{option.name}} <-- I still want result to show up
    </div>
    <div ng-if="row.options.length === 0">
       <label>No Data</label>
    </div>

</ng-repeat>

Upvotes: 2

Related Questions