I created a pagination directive that takes two arguments; current page and total number of pages.
<pagination page="page" number-of-pages="numberOfPages"></pagination>
The problem is that I will know the value of numberOfPages after calling AJAX (via ng-resource). But my directive is already done before the AJAX call is made.
app.controller('MyController', function ($scope, $routeParams) { $scope.page = +$routeParams.page || 1, $scope.numberOfPages = 23; // This will work just fine MyResource.query({ "page": $scope.page, "per_page": 100 }, function (response) { //This won't work since the directive is already rendered $scope.numberOfPages = response.meta.number_of_pages; }); });
I prefer to wait with the rendering of my controller template until the AJAX call completes.
In Plan B, a template with a template for directives will be added when an AJAX call is made.
I am stuck in developing both scenarios.
angularjs angularjs-directive angularjs-resource
Erik nijland
source share