我从一个组件路由到另一个组件,但它在屏幕上闪烁一秒钟,然后将其销毁并转到上一个组件。我正在使用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' });
}
}
而不仅仅是
[routerLink]="['/CostofOwnership/ownership-result', cons.name]
为什么会发生这种情况(这种情况发生在Safari而不是Chrome)?