0

I am using angular routers

app.config(function($routeProvider){

$routeProvider

        .when('/comment/list',{
                templateUrl: 'commentList.htm',
                controller: 'mainController'

        })

});

<td ng-show="btnUADetails" ng-click="loadPage('commentList', x.userName);">
           <a class="detailButton" href="#/comment/list"></a>                   
</td>

and here is my angular function

 $scope.loadPage = function(pageId, id) {
        if(pageId == "commentList")
            {

                    $scope.getServerData($scope.generateUrl(pageId, 'json', id)).then(function(result){
                    $scope.serverComment=result;
                });
            }
            else{
                //do something
            }
}  

Before $HTTP returns response html page loads and i am getting clean data in html table . Can i load this page after my functions returns result ? Or load html file first and load it again when functions returns result ?

JP Dolocanog
  • 451
  • 3
  • 19
  • This is not a duplicate of the said question. He asks how to resolve the data before the page loads and that specifically for routing in angular, not how to use promises in general. To answer the question: you can use the routing config `resolve`. See the `resolve` on the `route` in [the documentation](https://docs.angularjs.org/api/ngRoute/provider/$routeProvider) – devqon Jul 26 '17 at 08:15
  • It is good but can not understand can i write if clause in resolve ? i want to check if 'if' clause returns true than i want to load this page, can i do it ? –  Jul 26 '17 at 08:31
  • Yes you can use promises in the resolve, something like: `resolve: ["$q", "myService", function($q, myService) { var defer = $q.defer(); myService.doSomething().then(function(result) { if(..) defer.resolve(); else defer.reject(); return defer.promise; }` – devqon Jul 26 '17 at 08:37
  • yes but i am calling method from html . i have ng-repeat x in items. and then from html ng-click i am calling myfunction(x.id) how can i get this parameter in resolve ? –  Jul 26 '17 at 08:40

0 Answers0