jan*_*s83 0 javascript typescript ionic-framework angular
我正在阅读Angular 5 http 教程.一切都运行良好,直到我坚持这个奇怪的结构我的离子项目抛出错误,"没有定义".
/**
* Handle Http operation that failed.
* Let the app continue.
* @param operation - name of the operation that failed
* @param result - optional value to return as the observable result
*/
private handleError<T> (operation = 'operation', result?: T) {
return (error: any): Observable<T> => {
// TODO: send the error to remote logging infrastructure
console.error(error); // log to console instead
// TODO: better job of transforming error for user consumption
this.log(`${operation} failed: ${error.message}`);
// Let the app keep running by returning an empty result.
return of(result as T);
};
}
Run Code Online (Sandbox Code Playgroud)
我累了谷歌搜索这种"方法",但没有成功.这是教程中的错误吗?也许有些图书馆?
of是一个单独的功能.您需要of从rxjs包中导入功能.RxJS 5.5及更高版本将此技术与单独的函数一起使用.您需要导入的大多数功能,这使您可以拥有干净的代码,还可以使用捆绑工具进行一些优化.
import { of } from 'rxjs/observable/of'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
393 次 |
| 最近记录: |