angular - 通过 Chrome 使用 Angular 12 在 TypeScript 中调试 API
问题描述
我无法从 SO 中找到解决方案。
如何调试和检查hello
下面?
getHero(): void {
const id = parseInt(this.route.snapshot.paramMap.get('id') !, 10);
this.heroService.getHero(id)
.subscribe(hero => this.hero = hero);
}
https://stackblitz.com/angular/roynrxqmenv?file=src%2Fapp%2Fhero-detail%2Fhero-detail.component.ts
任何想法?
同样,如何调试getHero
下面的返回值。以下h
不显示任何内容。
getHero(id: number): Observable<Hero> {
const url = `${this.heroesUrl}/${id}`;
return this.http.get<Hero>(url).pipe(
tap(h => this.log(`fetched hero id=${id}`)),
catchError(this.handleError<Hero>(`getHero id=${id}`))
);
}
https://stackblitz.com/angular/roynrxqmenv?file=src%2Fapp%2Fhero.service.ts
解决方案
最简单的方法是将单行语句包装在回调函数中{}
getHero(): void {
const id = parseInt(this.route.snapshot.paramMap.get('id') !, 10);
this.heroService.getHero(id)
.subscribe(hero => {
// debugger;
this.hero = hero;
});
}
这将允许您在浏览器中的正确位置放置断点。
你也可以debugger
在里面放一个,以防万一。
推荐阅读
- c# - 以编程方式处理 C# UI 表单元素的动态范围
- javascript - Node中函数之间的数据接口
- awk - 在 awk 中比较当前行和下一行
- r - 如何将一些样本名称更改为R中PCA中的点或星号等符号?
- ios - 如何在 Swift 5 中检查字符串是否以字母开头?
- firebird - 如何解决 PSQL 函数中的 Firebird 搜索案例错误
- php - 在使用 Laravel 期间执行迁移时有什么方法可以避免错误?
- swift - Swift,与 containerView 相关的新手问题。如何使孩子的故事板视图控制器与容器视图的大小相同
- python - 如何使用openpyxl将qtablewidget数据保存到excel文件中
- css - vue类绑定对象的变量