本文整理汇总了TypeScript中rxjs/Rx.Observer类的典型用法代码示例。如果您正苦于以下问题:TypeScript Observer类的具体用法?TypeScript Observer怎么用?TypeScript Observer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Observer类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: Notification
return this._http.post(this._apiBaseUrl, _n, { headers: headers }).map(response => response.json()).subscribe(data => {
this._dataStore.tracks.push(data[0]);
this._tracksObserver.next(this._dataStore.tracks);
this._newestTrackObserver.next(data[0]);
let trName = data[0].trackname;
this._notes.add(new Notification('info', trName + ' bætt við.'));
}, error => { this._notes.add(new Notification('error', 'Ekki tókst að tengjast gagnagrunni. Lagi ekki bætt við.')); });
示例2:
let obs: Observable<any> = Observable.create((observer: Observer<any>) => {
if (user.Email == "arun.thakur@mail.com" && user.Password == "123456") {
observer.next(true);
}
else {
observer.error("Invalid Credentials");
}
observer.complete();
//return () => { console.log("disposable called..."); }; //dispose observable
});
示例3:
(observer: Observer<any>) => {
if (!this.needsUpdate(url)) {
observer.next(this.cacheMap[url].data);
observer.complete();
}
this.call("get", url).subscribe(
res => {
this.storeData(url, res.json());
observer.next(this.cacheMap[url].data);
observer.complete();
}
);
}
示例4: Notification
this._http.get(_url).map(response => response.json()).subscribe(data => {
// Set selectedProject
this._dataStore.selectedProject = data[0];
this._selectedProjectObserver.next(this._dataStore.selectedProject);
}, error => { this._notes.add(new Notification('error', 'Ekki tóst að sækja verkefni í gagnagrunninn.')); });
示例5: Notification
this._http.delete(_url).subscribe(response => {
// DELETE CREDITS FROM DATA STORE AND PUSH IT TO THE STREAM
this._dataStore.credits = this._dataStore.credits.filter(credit => credit.projecttrackid !== track.id);
this._creditsObserver.next(this._dataStore.credits);
}, error => { this._notes.add(new Notification('error', 'Ekki tókst að ná eyða flytjanda.')); });
示例6:
position => {
const coordinate: Coordinate = {
latitude: position.coords.latitude,
longitude: position.coords.longitude
};
observer.next(coordinate);
observer.complete();
},
示例7:
xhr.onreadystatechange = () => {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
observer.next("test");
observer.complete();
} else {
observer.error(xhr.response);
}
}
};
示例8:
}).then((cmpRef: ComponentRef<TooltipComponent>) => {
// Store reference to TooltipComponent
this._toolTipCmp = cmpRef;
// Append it to DOM
this.viewContainer.element.nativeElement.appendChild(cmpRef.location.nativeElement);
// Resolve the component
observer.next(this._toolTipCmp);
observer.complete();
});
示例9: function
req.onload = function() {
if (req.status == 200) {
// If the status is 200, meaning there have been no problems,
// Yield the result to listeners and complete the sequence
observer.next(req.response);
observer.complete();
}
else {
// Otherwise, signal to listeners that there has been an error
observer.error(new Error(req.statusText));
}
};
示例10:
Observable.forkJoin(fetchPages).subscribe(datas => {
let dataArray: any = datas;
dataArray.forEach((data: any) => {
comments = comments.concat(data.values);
},
(err: any) => {
observer.error(err);
});
let modelComments: Comment[] = comments.map((jsonComment: any) => {
console.log(jsonComment);
let content: CommentContent = {
html: jsonComment.content.html,
markup: jsonComment.content.markup,
raw: jsonComment.content.raw
};
let author: User = {
userName: jsonComment.user.username,
displayName: jsonComment.user.display_name,
uuid: jsonComment.user.uuid
};
let comment: Comment = {
content: content,
author: author
};
return comment;
});
// Return the result to the observers
observer.next(modelComments);
},