http 구독에서 Angular2 서비스를 구독 취소하는 가장 좋은 방법은 무엇입니까?Angular2 : 서비스에서 관찰 가능한 http에서 수신 거부
현재이 작업을 수행하고 있지만 이것이 최선의 방법인지 잘 모르겠습니다.
import { Injectable } from "@angular/core";
import { Http } from "@angular/http";
import { Subject } from "rxjs/Subject";
import { ISubscription } from "rxjs/Subscription";
@Injectable()
export class SearchService {
private _searchSource = new Subject<any>();
public search$ = this._searchSource.asObservable();
constructor(private _http: Http) {}
public search(value: string) {
let sub: ISubscription = this._http.get("/api/search?value=" + value)
.map(response => <any>response.json())
.do(data => this._searchSource.next(data))
.finally(() => sub.unsubscribe()).subscribe();
}
}
관찰 가능 항목이 완료되면 수신자 부담을 덜어주고 무의미한 것으로 보입니다. –
@ günter-zöchbauer 글쎄 그것은 내 질문이 의미가있는 경우 내 질문이 아니었다 : 가장 좋은 방법은 무엇인가? 그래서? –
나는 감각이없는 것들에 대한 모범 사례가 없다고 생각한다 : 아마도 아마도 -하지 말라. –