I am currently utilizing Angular along with the Material library in my project. I am facing an issue with two nested ng-repeat loops within md-tables. The problem lies in the fact that the variable is getting overridden with each request in the nested loops. Although I could combine the requests and iterate through them, the dynamic pagination feature would not be functional.
Below is the index file containing the tables:
<div ng-init="getCategories()" flex>
...
<div class="content-main" ng-repeat="category in categories">
...
<md-content>
<table md-table ng-init="getBooks(category.id)">
...
<tr md-row ng-repeat="book in books | orderBy: query.order ">
<td md-cell>
<span>{{ book.title }}</span>
</td>
...
</md-content>
<md-table-pagination md-limit="query.limit"
md-limit-options="limit"
md-page="query.page"
md-page-select="options.pageSelect"
md-total="{{booksCount}}"
md-boundary-links="options.boundaryLinks">
</md-table-pagination>
Here are the simplified Angular controller functions:
$scope.getCategories = function () {
\\perform get request
$scope.categories = resp.data.rows;
}
$scope.getBooks = function () {
\\perform get request with pagination and search parameters
$scope.books = resp.data.rows;
$scope.booksCount = resp.data.amount;
}
As a result, every request to getBooks overrides the "books" variable, causing, for example, the issue of seeing the same books (from category 2) for both categories.
Category 1
Book C Book D
Category 2
Book C Book D
(incorrect)
However, I should actually have different books for Category 1:
Category 1
Book A Book B
Category 2
Book C Book D
(correct)