【发布时间】:2023-03-30 00:11:01
【问题描述】:
我正在将我的 get 转移到我的应用程序的不同 service.ts 但我得到了这个 error
这是我的代码: AppComponent.ts
import { Component } from '@angular/core';
import {Http } from '@angular/http';
import 'rxjs/Rx';
import {FeatureService} from "./Feature.service";
@Component({
selector: 'my-app',
providers: [FeatureService],
template: `<h1>Hier staat de json die we uit de test hebben gehaald</h1>
<p>Deze json hallen we van vert.x af en kunnen we converten naar een mooie rapport.</p>
<button (click)="clicked()">Haal test Json op</button>
<button (click)="getFeatures()">features</button>
<button (click)="getScenarios()">scenarios</button>
{{leerling}}
`,
})
export class AppComponent {
titel = "";
leerling: any;
leerlingUrl = 'http://localhost:8080/testresultaten';
public clicked(){
this.http.get(this.leerlingUrl).map(res => res.json())
.subscribe(data => this.leerling = JSON.stringify(data)
,error => this.leerling = "error", () => console.log("Json got good"));
}
public getFeatures(){
this.leerling = FeatureService.getFeature();
}
public getScenarios(){
this.http.get('http://localhost:8080/features/1/scenarios').map(res => res.json()).subscribe(data => this.leerling = JSON.stringify(data),error => this.leerling = "error", () => console.log("Json got good"));
}
constructor(private http : Http, private featureService : FeatureService){
}
}
这是我的 Feature.service.ts
import {Http} from "@angular/http";
export class FeatureService{
private static http : Http;
static getFeature(){
return this.http.get('http://localhost:8080/features')
.map(data => data.toString());
}
}
旧的(clicked() 和 getScenarios())仍然有效,但 FeatureService.getFeature() 无效
【问题讨论】: