(Angular-ui-router) Show loading animation during resolve process

后端 未结 11 812
生来不讨喜
生来不讨喜 2020-12-07 07:12

This is a two part question:

  1. I am using the resolve property inside $stateProvider.state() to grab certain server data before loading the controller. How wo

11条回答
  •  無奈伤痛
    2020-12-07 07:55

    If anyone is using ngRoute, waiting on resolve before loading the next view, and using angular-bootstrap-ui for ui, you can do the following:

    app.config([
      "$routeProvider", "$locationProvider", function($routeProvider, $locationProvider) {
        return $routeProvider.when("/seasons/:seasonId", {
          templateUrl: "season-manage.html",
          controller: "SeasonManageController",
          resolve: {
            season: [
              "$route", "$q", "$http", "$modal", function($route, $q, $http, $modal) {
                var modal, promise, seasonId;
                modal = $modal.open({
                  backdrop: "static",
                  template: "
    \n
    \n

    \n Loading...\n

    \n
    \n
    \n \n \n
    \n
    ", keyboard: false, size: "lg" }); promise = $q.defer(); seasonId = $route.current.params.seasonId; $http.get("/api/match/seasons/" + seasonId).success(function(data) { modal.close(); promise.resolve(data); }).error(function(data) { modal.close(); promise.reject(data); }); return promise.promise; } ] } }); } ]);

提交回复
热议问题