国家的角度承诺解决了空洞

时间:2018-04-29 00:31:36

标签: angularjs

我对Angular一点都不熟悉,并且在深陷的情况下很开心。请原谅无知并善待。我们有以下状态:

.state('busList', {
        //after button
        url: '/bus',
        templateUrl: 'app/bus/search/list.html',
        controller: 'BusListCtrl',
        resolve: {
            oneway: function ($stateParams, Vuka, $log) {
                return searchBusTrip($stateParams.departureLocation.locationId, $stateParams.arrivalLocation.locationId, $stateParams.departureDate, $stateParams.numPassengers).$promise;
            },
            returns: function ($stateParams, Vuka) {
                return searchBusTrip($stateParams.arrivalLocation.locationId, $stateParams.departureLocation.locationId, $stateParams.returnDate, $stateParams.numPassengers).$promise;
            }
        },
        params: {
            departureLocation: undefined,
            arrivalLocation: undefined,
            departureDate: undefined,
            returnDate: undefined,
            numPassengers: undefined,
            oneWay: false
        }
    })

searchBusTrip如下:

searchBusTrip: function (p_departureLocationId, p_destinationLocationId, p_departureDate, p_numberOfPassengers) {
        var intercape_response = $http({
            //url: c_url_man + 'SearchBusTrip',
            url: c_url + 'SearchBusTrip',
            method: 'POST',
            data: {
                provider: 'Intercape',
                sessionId: guid(),
                departureLocationId: p_departureLocationId,
                destinationLocationId: p_destinationLocationId,
                departureDate: p_departureDate,
                numberOfPassengers: p_numberOfPassengers
            }
          }).then(function successCallback(response) {
            response.data.tripSegments;
            angular.forEach(response.data.tripSegments, function (tripSegment) {
                var arrivalDateObj = new Date(tripSegment.arrivalDate);
                var departureDateObj = new Date(tripSegment.departureDate);
                tripSegment.timeSpace = Math.floor((((arrivalDateObj / 1000) - (departureDateObj / 1000)) / 3600));
                listings.push(tripSegment);
                //console.log(tripSegment.provider);
            });
          }).catch(function errorCallback(response) {
              //error
          }).finally(function() {
            alert(listings);
          }); return listings;

提供列表的警报正在给出正确的填充结果。但是,这会在新页面开始加载后几秒钟发生。因此,我假设国家决心的回报是空的。我已经解决了这个问题:

How to force AngularJS resource resolution with ui-router 我已经尝试在searchBusTrip函数中返回列表。我试图添加当时&最终以单向返回并返回.state。我试图延迟stateChangeStart,以及无数其他选项。我意识到我缺乏对Angular的正确理解是最大的问题。

非常感谢任何帮助。

0 个答案:

没有答案