(решено -> проверить внизу) Мне нужно вызвать URL на моем djangoserver, но (возвращение угловых точек) не вызывает его.console.log () показывает правильный URL, а также вызов этого URL-адреса вручную работает так, как я хотел.что я делаю не так?
script_dashboard.js
...
var win = window.open("http://127.0.0.1:4200/" + values.toString(), '_blank');
...
app.components.ts
export class AppComponent implements OnInit {
constructor(private route: ActivatedRoute, private apiService: ApiService, private location: Location, private http: HttpClient) {
}
getFirstData(): void {
const dbKey = this.route.snapshot.paramMap.get('key');
console.log(dbKey);
this.apiService.getAllMeasurements(dbKey);
}
ngOnInit() {
this.getFirstData()
}
}
api.service.ts
export class ApiService {
baseurl = "http://127.0.0.1:8000";
httpHeaders = new HttpHeaders({ 'Content-type': 'application/json' })
constructor(private http: HttpClient) { }
getAllMeasurements(key: string): Observable<any> {
console.log("EXECITUNG")
// return this.http.get(this.baseurl + '/reload_site/?keys=' + key,
console.log(this.baseurl + '/tviewer/reload_site/?keys=' + key)
return this.http.get(this.baseurl + '/tviewer/reload_site/?keys=' + key,
{ headers: this.httpHeaders });
}
}
console.log в браузере
null
api.service.ts:15 EXECITUNG
api.service.ts:17 http://127.0.0.1:8000/tviewer/reload_site/?keys=null
core.js:16828 Angular is running in the development mode. Call enableProdMode() to enable the production mode.
app.component.ts:20 1.1.1.1,T
api.service.ts:15 EXECITUNG
api.service.ts:17 http://127.0.0.1:8000/tviewer/reload_site/?keys=1.1.1.1,T
как вы видите
.. api.service.ts: 17 http://127.0.0.1:8000/tviewer/reload_site/?keys=1.1.1.1,T..
- это правильный URL, но он не вызывается.
Some1 имеет идею?
Решение:
app.components.ts
this.apiService.getAllMeasurements(dbKey).subscribe(response => this.availableMeasurements = response);