本文整理汇总了TypeScript中rxjs/Rx.Observable.throw方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Observable.throw方法的具体用法?TypeScript Observable.throw怎么用?TypeScript Observable.throw使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rxjs/Rx.Observable
的用法示例。
在下文中一共展示了Observable.throw方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: constructor
constructor(fb:FormBuilder) {
this.formModel = fb.group({
search: []
});
var searchControl = this.formModel.find('search');
searchControl.valueChanges
.debounceTime(400)
.map(str => (str.replace(' ', '-')))
.subscribe(x => console.log(x));
/** travel search */
var startDates = [];
var startDate = new Date();
for (var day = -2; day < 2; day++) {
var date = new Date(
startDate.getFullYear(),
startDate.getMonth(),
startDate.getDate() + day
);
startDates.push(date);
}
Observable
.fromArray(startDates)
.map(date => {
console.log("Getting deals for date: " + date);
return [1, 2, 3];
})
.subscribe(x => console.log(x));
/** interval */
// Observable
// .interval(1000)
// .subscribe(x => console.log(x))
// Observable
// .interval(1000)
// .flatMap(x => {
// console.log("Calling server to get latest news..");
// return Observable.of([1, 2, 3]);
// })
// .subscribe(news => console.log(news));
/** delay */
var userStream = Observable.of({
userId: 1, userName: 'chanu'
}).delay(2000);
/** join */
var tweetsStream = Observable.of([1, 2, 3]).delay(1500);
Observable
.forkJoin(userStream, tweetsStream)
.map(joined => Object({user: joined[0], tweets: joined[1]}))
.subscribe(result => console.log(result));
/** error handling */
var observable = Observable.throw(new Error("Something failed!"));
observable
.subscribe(
x => console.log(x),
error => console.log(error));
/** retry */
var counter = 0;
var ajaxCall = Observable
.of('url')
.flatMap(() => {
if (++counter < 2)
return Observable.throw(new Error("Request failed!"));
return Observable.of([1, 2, 3]);
})
.retry(3)
.subscribe(
x => console.log("Response from retry: " + x),
error => console.log(error)
);
/** catching and continuing */
var remoteDataStream = Observable.throw(new Error("Something is wrong!"));
remoteDataStream.catch(err => {
var localDataStream = Observable.of([1, 2, 3]);
return localDataStream;
})
.subscribe(x => console.log("Catching and continuing: " + x));
/** Completed */
Observable
.throw(new Error("error"))
.subscribe(
x => console.log(x),
error => console.log(error),
() => console.log("Completed"));
Observable
.fromArray([1, 2, 3])
.subscribe(
//.........这里部分代码省略.........
示例2: handleError
private handleError(error: any) {
// console.log("Error", error);
let errMsg = error.message || 'Server error';
return Observable.throw(errMsg);
}
示例3: handleError
private handleError (error: Response) {
console.error(error);
return Observable.throw(error.json().error || 'Server error');
}
示例4: handleError
private handleError(error: Response) {
this.notificationsService.error(this.messagesService.oops,
this.messagesService.somethingWentWrong);
return Observable.throw('Server error');
}
示例5: spyOn
spyOn(instance.imagesService, 'getProfileImages').and.callFake(() => { return Observable.throw(new Error()); });
示例6:
observable1 = constructorZone1.run(() => {
return Rx.Observable.throw(error);
});
示例7:
.catch(ex => {
this._synchronizedExcecutionInfo.next(ExecutionInfo.createFail<TResult>());
this._exceptions.next(ex);
return Observable.throw(ex);
})
示例8: _handleError
private _handleError(error: Response) {
return Rx.Observable.throw(error || 'Server error');
}
示例9: Error
}).catch((error: any) => {
// console.log(error.status, "service")
if (error.status === 409) {
return Observable.throw(new Error(error.status));
}
}
示例10: handleError
private handleError(error:any) {
let errMsg = (error.message) ? error.message :
error.status ? `${error.status} - ${error.statusText}` : 'Server error';
return Observable.throw(errMsg);
}