It is invalid for the HttpClient callback method to use the injection object method in Angular5?

1. Use angular HttpClient to request backend data to get the title. Setting the title through @ angular/platform/Title service has no effect. Please give me some advice and how to solve it?

2. The code snippet is as follows. Angular version: 5.2.0, there is no error message, that is, the method call does not meet expectations

import {Title} from "@angular/platform-browser";
import {HttpClient, HttpErrorResponse, HttpResponse} from "@angular/common/http";

constructor(private titleService: Title) {

 }


 
  ngOnInit() {
    let that = this;
    that.titleService.setTitle(""); //
    this.http.get<any>("/api/dingtalk/get-file-title/"+1,{ observe: "response"}).subscribe(
      (res: HttpResponse<any>) => {
        that.titleService.setTitle(""); //
        console.log("success!" ,that.titleService.getTitle())
      },
      (res: HttpErrorResponse) => console.log(res.error)
    );
  }

console.log ("stories!", that.titleService.getTitle ()) output:

:

Mar.05,2021

determine whether the request response is normal. The success callback


has found the cause. It is not an angular problem. This problem only occurs in dingtalk browsers. You need to use the dd.biz.navigation.setTitle method of dingtalk to set the title.

Menu