Laziale Laziale - 4 months ago 17
AngularJS Question

angularjs display length of items where property equals

I have this html markup:

<table class="table tenant-table text-center">
<tr>
<th class="text-center">Property Number</th>
<th class="text-center">Location</th>
<th class="text-center">Cost / Value</th>
<th class="text-center">Commercial Tenants</th>
<th class="text-center">Multy-family Tenants</th>
<th></th>
</tr>

<tr ng-repeat="property in purchasePropertyData.properties">
<td>{{property.PropertyType}}</td>
<td>{{property.City}}</td>
<td>&euro;{{property.CurrentValue}}</td>
<td>{{property.Tenants.length}}</td> // where tenanttype = 1
<td>{{property.Tenants.length}}</td> // where tenanttype = 2
</tr>
</table>


I want to know if I can directly access the length of the tenants in the property where tenanttype equals 1 or 2.

I know there are ways in the controller I can calculate this but I want to know if its possible to do this directly.

Thanks

Answer

You can try this:

<tr ng-repeat="property in purchasePropertyData.properties">
    <td ng-if='property.Tenants' ng-repeat="item in property.Tenants | filter : {tenanttype:1}" ng-if="$last">{{$index + 1}}</td>// where tenanttype = 1
    <td ng-if='property.Tenants' ng-repeat="item in property.Tenants | filter : {tenanttype:2}" ng-if="$last">{{$index + 1}}</td>// where tenanttype = 2
    <td ng-if='!property.Tenants'>0</td>
</tr>