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:
: