I am beginning to run into this problem a lot. The scenario is that I have a partial that I would like to reuse. The problem is, I would have to overwrite my previous data in the scope in order for the new data to show up in the partial. I would like to know how people get around this.
Here is an example:
I have tabs that all use $scope.pebbles
and share the same partial. For each tab, I would like different data to be populated. So naturally, I would just make a new request for data and store it back into the variable to change the data, for example: $scope.pebbles = getPebbles(color)
. The problem with this is that I would have to make a new request each time I change the tab. Is there a better way around this without having a huge partial?
overview.html:
<tab>
<tab-heading>
<i class="icon-bell"></i> All
</tab-heading>
<div class="tab-content">
<div ng-include="'views/partials/_pebbles.html'"></div>
</div>
</tab>
<tab ng-repeat="color in colors">
<tab-heading ng-click="tab(color)">
{{color}}
</tab-heading>
<div class="tab-content">
<div ng-include="'views/partials/_pebbles.html'"></div>
</div>
</tab>
_pebbles.html:
<table class="table table-striped table-bordered bootstrap-datatable datatable">
<thead>
<tr>
<th>Pebble Name</th>
<th>Pebble Type</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="pebble in pebbles">
<td>{{pebble.name}}</td>
<td>{{pebble.type}}</td>
</tr>
</tbody>
</table>
Controller:
$scope.colors = ['blue','red','orange','purple']
$scope.pebbles = getPebbles() // http factory, makes a request for data
$scope.tab = function (color) {
$scope.pebbles = getPebbles(color)
}