当重新加载应用程序页面时,我的参数丢失了

时间:2019-08-02 14:19:22

标签: angular typescript

我有一个错误问题。当我刷新移动应用程序的页面时,部分参数会丢失。 错误地传递参数时,“ rerdirect”将导致“ /”而不是返回相应的对象。

我正在使用Angular 8和Typescript。我试图解决它再次创建参数,但这不起作用。

当重新加载“参数”不完整时,这是接收参数的函数。 然后重定向变为“ /”。

    searchForm(toolKey, params): EventEmitter<any> {
    this.toolKey = toolKey;
    this.getSearchFormCobus(params).first().subscribe(
      (response) => {
        if (response['redirect']) {
          this.event.emit(response['redirect']);
          return;
        }
        this.searchFormData = this.searchFormService.initSearchFormData(this.searchFormData);
        this.initSearchFormData();
        this.searchFormData = this.searchFormService.resolveConfig(this.searchFormData, response);
        this.searchFormData.relations = response.relations;
        this.searchFormData.passengers = response.passengersInfo;
        this.searchFormData.numTraveling = response.config.numberOfPassengers;
        this.searchFormData.authorization = response.authorizationInfo;
        this.searchFormData.transportingAirlines =
          [response.authorizationInfo.transportingAirlineDefault];
        this.event.emit(this.searchFormData);
      },
      (error) => {
        this.event.emit(Observable.throw(error));
      }
    );

    return this.event;
  }

  initSearchFormData() {}

  getSearchFormCobus(params): Observable<any> {
    return this.http.post(
      `${this.config.get('apiUrl')}/api/v1/flights/cobus_form_config.json`,
      params,
      { headers: this.headerHelper.getHeadersJson() }
    );
  }

从这里调用该函数。

this.searchFormService.searchForm(this.toolKey, this.params.data).first().subscribe((response) => {
      if (response.hasOwnProperty('error') && response.error !== '') {
        this.initHasError = true;
        this.loading.hide('searchForm');
        return;
      }
      if (response['redirect']) {
        return RedirectHelper.root(this.navCtrl, response['redirect']);
      }
      this.searchFormConfigData = response;
      this.searchButtonDisabled = false;

      if (this.toolKey === 'ticketing') {
        this.flightProgramService.getApplicablePrograms(this.searchFormConfigData.passengers.remainingProgramsDetails)
          .subscribe((flightPrograms) => {
            this.flightPrograms = flightPrograms;
            this.loading.hide('flightPrograms');
            if (this.flightPrograms.length > 0) {
              this.shouldDisplayFlightPrograms = true;
            }
          }
        );
      } else {
        this.loading.hide('flightPrograms');
      }

      if (this.searchFormConfigData.allowedToBook === false) {
        this.searchButtonDisabled = true;
      }

      if (!this.welcomeMessage && this.searchFormConfigData.welcomeMessage !== '') {
        this.storage.set('welcomeMessage', this.searchFormConfigData.welcomeMessage);
        this.welcomeMessage = this.searchFormConfigData.welcomeMessage;
      } else {
        this.storage.get('welcomeMessage').first().subscribe((value) => {
          this.welcomeMessage = value;
        });

参数在Nav Params中加载。

import { IonicPage, AlertController, NavController, ModalController, NavParams, Events } from 'ionic-angular';

constructor(private navCtrl: NavController,
              private alertCtrl: AlertController,
              public loading: LoadingHelper,
              private translate: TranslateService,
              private events: Events,
              private fb: FormBuilder,
              private modalCtrl: ModalController,
              private searchFormFactory: SearchFormFactory,
              public params: NavParams,
              public storage: StorageService,
              private ga: GoogleAnalytics,
              private fbHelpers: FacebookEventsHelpers,
              private flightProgramService: FlightProgramService) {
  }

如何在重新加载应用程序页面时避免丢失参数?

0 个答案:

没有答案