组件在创建后立即销毁

时间:2018-04-12 15:13:02

标签: angular

我从一个组件路由到另一个组件,但它在屏幕上闪烁一秒钟,然后将其销毁并转到上一个组件。我正在使用Angular 4,我可以使用什么来查看导致组件被破坏的原因。

编辑 - 这是我从另一个组件中路由到的组件,该组件在我在Safari中路由到它后立即销毁,但在Chrome中没有这样做。

    import { Component, OnInit } from '@angular/core';
    import {AngularFireDatabase, FirebaseListObservable, FirebaseObjectObservable} from 'angularfire2/database';
    import {AuthService} from '../auth/auth.service';
    import {NavigationEnd, Router, ActivatedRoute} from '@angular/router';
    import * as jsPDF from 'jspdf';
    import * as html2canvas from 'html2canvas';

    import {isNumber} from 'util';
    import {isPlatformBrowser} from '@angular/common';
    import {Subscription} from 'rxjs/Subscription';

    @Component({
      templateUrl: './ownership-result.component.html',
      styles: ['.mat-slider-track-fill{background-color:#20a8d8 !important;}']
    })

    export class OwnershipResultComponent {
      uid: string;
      costs = [];
      submitted: FirebaseListObservable<any>;
      typeForm: string;
      constants = {
        valveNumber: 0,
        MTBF: 0,
        failPercent: 0,
        opportunityCost: 0
      };
      constructor( public authService: AuthService, db: AngularFireDatabase, private router: Router, private route: ActivatedRoute) {
        this.authService.user.subscribe(

          (auth) => {
            if (auth === null) {
              this.router.navigate(['auth']);
            } else {
              this.uid = auth.uid;
              this.route.paramMap
                .subscribe(params => {
                  this.typeForm = params.get('typeOf');
                })
              this.submitted = db.list('/ownership/answers/' + this.uid + 
    '/saved/' + this.typeForm +'/add');
              db.object('/ownership/answers/' + this.uid + '/saved/' + this.typeForm +'/constants').subscribe(constants => {
                this.constants.valveNumber = constants.valveNumber;
                this.constants.MTBF = constants.MTBF;
                this.constants.failPercent = constants.failPercent;
                this.constants.opportunityCost = constants.opportunityCost;
              });
              this.makeArray();
            }
          }
        );
        window.scrollTo(0, 0);
      }
scrollToDetails() {
    this.detailhide = !this.detailhide
    const elemnt = document.getElementById('pdfprint');
    elemnt.scrollIntoView({ behavior: 'smooth' });
  }
    }

编辑 - 进一步了解正在发生的事情并看到它的第一个路由到 http://localhost:4200/?changeName=Cost+of+a+new+valve&default=7000&changeName=Cost+of+a+new+actuator+assembly&default=3000&changeName=Cost+to+repair+the+valve+%28Repair+kit+and+labour%29&default=1800&changeName=Cost+to+remove+and+re-install+the+valve&default=5000&changeName=Cost+to+generate+a+purchase+order&default=350&changeName=Cost+to+decontaminate+a+valve+that+has+been+in+service&default=450&changeName=Cost+of+packaging+and+shipping+the+valve&default=900&changeName=Cost+to+test+a+new%2Frepaired+valve+before+it+is+installed&default=65&changeName=Cost+of+storage+for+spare+valves%2Frepair+kits&default=40&changeName=Cost+to+insulate+the+valve&default=450&changeName=Cost+of+an+unscheduled+shutdown&default=0#/CostofOwnership/ownership-result/Default

而不仅仅是

[routerLink]="['/CostofOwnership/ownership-result', cons.name]

为什么会发生这种情况(这种情况发生在Safari而不是Chrome)?

0 个答案:

没有答案