ObjectUnsubscribedError after using takeUntil
up vote
0
down vote
favorite
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?
angular rxjs
add a comment |
up vote
0
down vote
favorite
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?
angular rxjs
When do you callBuildView
?
– Explosion Pills
Nov 19 at 21:13
I call build view when a user clicks to load a project.
– Petey
Nov 19 at 21:18
Can you please provide a stackblitz so we can reproduce your error
– Batajus
Nov 19 at 21:36
1
You almost never want to callunsubscribe
on aSubject
instance: blog.angularindepth.com/rxjs-closed-subjects-1b6f76c1b63c
– cartant
Nov 19 at 23:24
maybe call this.ngUnsubscribe.next(); then this.ngUnsubscribe.complete(); before unsubscribe, according to the article
– Fan Cheung
Nov 20 at 5:43
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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?
angular rxjs
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?
angular rxjs
angular rxjs
edited Nov 19 at 21:19
asked Nov 19 at 21:10
Petey
197
197
When do you callBuildView
?
– Explosion Pills
Nov 19 at 21:13
I call build view when a user clicks to load a project.
– Petey
Nov 19 at 21:18
Can you please provide a stackblitz so we can reproduce your error
– Batajus
Nov 19 at 21:36
1
You almost never want to callunsubscribe
on aSubject
instance: blog.angularindepth.com/rxjs-closed-subjects-1b6f76c1b63c
– cartant
Nov 19 at 23:24
maybe call this.ngUnsubscribe.next(); then this.ngUnsubscribe.complete(); before unsubscribe, according to the article
– Fan Cheung
Nov 20 at 5:43
add a comment |
When do you callBuildView
?
– Explosion Pills
Nov 19 at 21:13
I call build view when a user clicks to load a project.
– Petey
Nov 19 at 21:18
Can you please provide a stackblitz so we can reproduce your error
– Batajus
Nov 19 at 21:36
1
You almost never want to callunsubscribe
on aSubject
instance: blog.angularindepth.com/rxjs-closed-subjects-1b6f76c1b63c
– cartant
Nov 19 at 23:24
maybe call this.ngUnsubscribe.next(); then this.ngUnsubscribe.complete(); before unsubscribe, according to the article
– Fan Cheung
Nov 20 at 5:43
When do you call
BuildView
?– Explosion Pills
Nov 19 at 21:13
When do you call
BuildView
?– Explosion Pills
Nov 19 at 21:13
I call build view when a user clicks to load a project.
– Petey
Nov 19 at 21:18
I call build view when a user clicks to load a project.
– Petey
Nov 19 at 21:18
Can you please provide a stackblitz so we can reproduce your error
– Batajus
Nov 19 at 21:36
Can you please provide a stackblitz so we can reproduce your error
– Batajus
Nov 19 at 21:36
1
1
You almost never want to call
unsubscribe
on a Subject
instance: blog.angularindepth.com/rxjs-closed-subjects-1b6f76c1b63c– cartant
Nov 19 at 23:24
You almost never want to call
unsubscribe
on a Subject
instance: blog.angularindepth.com/rxjs-closed-subjects-1b6f76c1b63c– cartant
Nov 19 at 23:24
maybe call this.ngUnsubscribe.next(); then this.ngUnsubscribe.complete(); before unsubscribe, according to the article
– Fan Cheung
Nov 20 at 5:43
maybe call this.ngUnsubscribe.next(); then this.ngUnsubscribe.complete(); before unsubscribe, according to the article
– Fan Cheung
Nov 20 at 5:43
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53382688%2fobjectunsubscribederror-after-using-takeuntil%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
When do you call
BuildView
?– Explosion Pills
Nov 19 at 21:13
I call build view when a user clicks to load a project.
– Petey
Nov 19 at 21:18
Can you please provide a stackblitz so we can reproduce your error
– Batajus
Nov 19 at 21:36
1
You almost never want to call
unsubscribe
on aSubject
instance: blog.angularindepth.com/rxjs-closed-subjects-1b6f76c1b63c– cartant
Nov 19 at 23:24
maybe call this.ngUnsubscribe.next(); then this.ngUnsubscribe.complete(); before unsubscribe, according to the article
– Fan Cheung
Nov 20 at 5:43