Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Angular CLI HTTP客户端获取数据但不刷新对象_C#_Angular - Fatal编程技术网

C# Angular CLI HTTP客户端获取数据但不刷新对象

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对象上

我正在开发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对象上设置

        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()
);