トランザクションステータスが '保留中'の場合は条件があり、トランザクションステータスが '完了'になるまでトランザクションをリロードしてサブスクライブします。 '拒否されました'。私のコードは初めてのみ、次回の訪問時にはページが空白ですが、データを登録解除したにもかかわらずデータはコンソールで実行されます。ページを更新せずに条件付きで角度2+リフレッシュリアルタイムデータを条件付きで
は、ここに私のコードです:
export class TransactionSummaryComponent implements OnInit, OnDestroy {
transaction: Models.Transaction = <Models.Transaction>{};
cancelling: boolean = false;
goToPayment: boolean = false;
private dataRefreshSub: Subscription;
private subscribeToDataSub: Subscription;
private timer: Observable<any>;
constructor(
private route: ActivatedRoute,
private router: Router,
private apiService: ApiService,
private zone: NgZone,
@Inject(PLATFORM_ID) private platformId: Object) { }
ngOnInit() {
if (isPlatformBrowser(this.platformId)) {
this.getTransaction();
}
}
getTransaction() {
this.route.paramMap
.switchMap((params: ParamMap) => this.apiService.getTransaction(params.get('id')))
.subscribe((transaction: Models.Transaction) => {
this.transaction = transaction;
if (this.transaction.status === 'Pending') {
this.refreshData();
}
});
}
refreshData() {
this.dataRefreshSub = this.route.paramMap
.switchMap((params: ParamMap) => this.apiService.getTransaction(params.get('id')))
.subscribe((transaction: Models.Transaction) => {
this.transaction = transaction;
this.subscribeToData();
});
}
subscribeToData() {
this.zone.runOutsideAngular(() => {
NgZone.assertNotInAngularZone();
this.timer = Observable.timer(1, 5000);
this.subscribeToDataSub = this.timer
.subscribe(() => {
this.refreshData();
});
});
}
ngOnDestroy() {
if (this.dataRefreshSub !== undefined) {
this.dataRefreshSub.unsubscribe();
}
if (this.subscribeToDataSub !== undefined) {
this.subscribeToDataSub.unsubscribe();
}
}
}
あなたは複数のネストされたサブスクリプションを持っています。これは常に反パターンであり、最新のリフレッシュサブスクリプションからのみサブスクライブしています。他のすべてのサブスクリプションへの参照は失われます。 – bryan60
そして何が問題なのですか?何を試しましたか?あなたはどんな問題に直面していますか?これは "私のコードplz"のウェブサイトを修正したものではありません.... – olivarra1
@ bryan60申し訳ありません、あなたは何を意味しているのですか、私はすべての定期購読を取り消そうとします –