throw

函数签名: throw(error: any, scheduler: Scheduler): Observable

在订阅上发出错误

示例

示例 1: 在订阅上抛出错误

( StackBlitz | jsBin | jsFiddle )

// RxJS v6+
import { throwError } from 'rxjs';

// 在订阅上使用指定值来发出错误
const source = throwError('This is an error!');
// 输出: 'Error: This is an error!'
const subscribe = source.subscribe({
  next: val => console.log(val),
  complete: () => console.log('Complete!'),
  error: val => console.log(`Error: ${val}`)
});

相关示例

其他资源

其他资源

:file_folder: 源码: https://github.com/ReactiveX/rxjs/blob/master/src/internal/observable/throwError.ts

results matching ""

    No results matching ""