code here:
@Injectable()
export class ProjectService {
create$: Rx.Subject<Response> = new Rx.Subject();
_create: Rx.Observable<Response> = this.create$.asObservable();
newProject: Rx.Subject<ProjectInfo> = new Rx.Subject();
get$: Rx.Subject<any> = new Rx.Subject();
_get: Rx.Observable<any> = this.get$.asObservable();
constructor(public _http: Http, public option: HeaderWithToken) {
this._create = this.newProject.flatMap(project => {
console.log("create",project);
return this._http.post(baseURL + "/project",
JSON.stringify(project), this.option.Option);
});
this._get = this._http
.get(baseURL + "/project", this.option.Option)
.do(x=>{
console.log("to get",x);
})
.map(res => res.json());
this._create
.map(x=>x.json())
.filter(res=>res.status==200)
.subscribe(this.get$);
this._get.subscribe(x => {
console.log("get:", x);
})
}
addProject(project: ProjectInfo) {
this.newProject.next(project);
}
getProject() {
return this._get;
}
}
I hope the stream will work as 1. when I call addProject => emit the value => trigger post request => when post response 200 continue the get request (_get stream) => I can subscribe the get$ stream other place to get all latest data.
actually: post successfull, but did not go into the get request, it seems that sth wrong with the code
this._create
.map(x=>x.json())
.filter(res=>res.status==200)
.subscribe(this.get$);
Please help!