So I have a bunch of http requests happening while I load different items to the screen. this is the basic layout
ngUnsubscribe: any = new Subject();
constructor(private service: Service){}
ngOnInit() {}
BuildView(data) {this.submitLayerservice.submitLayer(onLoadSubmitLayerFormat)
.pipe(takeUntil(this.ngUnsubscribe))
.subscribe( //logic happens here
)
}
ngOnDestroy() {
this.ngUnsubscribe.next();
this.ngUnsubscribe.unsubscribe();
}
Everything works fine and I see all of the requests get canceled when the component is destroyed. But when I go to load the project again I get this error and nothing shows up. I'm guessing it's because the ngUnsubscribe already happened? Not really sure. Most of the questions for this have to deal with Map.
EDIT: If i dont add this.ngUnsubscribe.unsubscribe(); The problem seems to be fixed. Should I not unsubscribe from this subject?
for anyone looking for this ,most likely the issue because the Subscription is not created again when you enter the component , so add in the ngWillEnter or ngDidEnter
ngUnsubscribe = new Subject();
make sure you have created the Subscription when you enter the view.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.