我希望我的 Angular 应用程序在将路由更改为某个路径之前解决一个承诺:
va.config(['$routeProvider', function($routeProvider) {
$routeProvider.
when('/sendungen', {templateUrl: '../partials/sendungen.php', controller: 'OverviewCtrl',resolve: {
shipments: oc.fetchAllShipments
}}).
// ...
}]);
函数 fetchAllShipments():
oc.fetchAllShipments = function(shipment){
shipment.fetchAllShipments().then(function(promise){
shipment.allShipments = promise.data;
});
};
然后控制器应将数据从装运服务复制到其$scope
:
va.controller('OverviewCtrl',function($scope,$http,shipment){
$scope.allShipments = shipment.allShipments;
});
只要我从应用程序中更改路由,一切都工作正常,例如我加载主页,然后切换到 /sendungen
但是,如果我已经在该路径上并决定刷新页面,则应用程序会在数据似乎被解析之前加载。这只是偶尔发生,似乎取决于他的脚本执行速度。
我如何防止这种行为?