[Library|Trunk]
complete previous commit -add unsubscribe methods for subscribe service git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@59827 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
parent
7ca179f3e8
commit
bc0628d9f7
|
@ -3,19 +3,25 @@ import {HttpClient} from '@angular/common/http';
|
|||
import {map, tap} from "rxjs/operators";
|
||||
import {CustomOptions} from "../../services/servicesUtils/customOptions.class";
|
||||
import {EnvProperties} from "../properties/env-properties";
|
||||
import {COOKIE} from "../../login/utils/helper.class";
|
||||
import {BehaviorSubject, Observable} from "rxjs";
|
||||
import {properties} from "../../../../environments/environment";
|
||||
import {BehaviorSubject, Observable, Subscriber} from "rxjs";
|
||||
|
||||
@Injectable()
|
||||
export class SubscribeService {
|
||||
private isSubscribedSubject: BehaviorSubject<boolean> = new BehaviorSubject(false);
|
||||
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
sub;
|
||||
ngOnDestroy() {
|
||||
this.clearSubscriptions();
|
||||
}
|
||||
clearSubscriptions(){
|
||||
if (this.sub instanceof Subscriber) {
|
||||
this.sub.unsubscribe();
|
||||
}
|
||||
}
|
||||
public initIsSubscribedToCommunity(properties: EnvProperties, pid: string) {
|
||||
let url = properties.adminToolsAPIURL + "/"+ properties.adminToolsPortalType +"/" + pid + "/is-subscriber/";
|
||||
this.http.get<boolean>(url, CustomOptions.getAuthOptionsWithBody()).subscribe((isSubscribed) => {
|
||||
this.sub = this.http.get<boolean>(url, CustomOptions.getAuthOptionsWithBody()).subscribe((isSubscribed) => {
|
||||
this.isSubscribedSubject.next(isSubscribed);
|
||||
}, error => {
|
||||
this.isSubscribedSubject.error(error);
|
||||
|
|
Loading…
Reference in New Issue