C# Angular CLI HTTP客户端获取数据但不刷新对象
我正在开发angular cli 7程序 我使用Httpclient从WebAPI.net读取数据 服务器上的My方法返回json值C# Angular CLI HTTP客户端获取数据但不刷新对象,c#,angular,C#,Angular,我正在开发angular cli 7程序 我使用Httpclient从WebAPI.net读取数据 服务器上的My方法返回json值 getTicket(ticketId: number) { return this.http.get<TicketModel>( SERVERURL/ticketId} ).pipe(map(res => res["result"] as TicketModel)); //调用get ticket的方法并在selectedTicket对象上
getTicket(ticketId: number) {
return this.http.get<TicketModel>(
SERVERURL/ticketId}
).pipe(map(res => res["result"] as TicketModel));
//调用get ticket的方法并在selectedTicket对象上设置
this.accountService.getTicket(ticketId).subscribe(res => this.selectedTicket = res);
服务获取数据,但不重新格式化此服务。已选择Dicket
我通常点击UI或其他按钮来刷新对象
-
تاریخ :
{{selectedTicket.requestTime | agoTime}}
-
واحد :
{{selectedTicket.departmentName}
很难确定,因为您尚未发布组件的代码。但是,如果您在Push上使用changeDetectionStrategy,那么如果您没有在组件中注入ChangeDetectorRef并在需要重新提交模板时使用它的markForCheck方法,则可能会发生这种情况
因此,首先将其添加到组件的构造函数参数中:
private changeDetectorRef: ChangeDetectorRef
然后更改将此设置为的代码。selectedTicket设置为:
this.accountService.getTicket(ticketId).subscribe(res => {
this.selectedTicket = res;
this.changeDetectorRef.markForCheck()
);
需要所有相关的代码!并以代码而不是图像的形式提供JSON示例!另一个问题可能是,如果您将票据模型作为输入传递到另一个组件中。
this.accountService.getTicket(ticketId).subscribe(res => {
this.selectedTicket = res;
this.changeDetectorRef.markForCheck()
);