나는 angularJs2를 처음 사용합니다.유형 Promise <void>을 Promise <customType []> 유형에 지정할 수 없습니다.
import { Injectable, OnInit } from '@angular/core';
import { customType } from '../models/currentJobs';
import { Headers, Http } from '@angular/http';
import 'rxjs/add/operator/toPromise';
@Injectable()
export class JobService implements OnInit {
constructor(private http: Http) { }
ngOnInit(): void {
this.getCurrentJobs();
}
private headers: Headers = new Headers({ 'Content-Type': 'application/json' });
private ordersUrl: string = 'http://localhost:35032/api/order/';
public orders: customType[];
getCurrentJobs(): Promise<customType[]> {
var jobs = this.http.get(this.ordersUrl)
.toPromise()
.then(response => {
this.orders = response.json() as customType[];
})
.catch(this.handleError);
return jobs;//this line throws error
}
private handleError(error: any): Promise<any> {
console.error('An error occurred', error);
return Promise.reject(error.message || error);
}
}
내가 오류
**TS2322 Build:Type 'Promise<void>' is not assignable to type 'Promise<customType[]>'.*
*
의 구성을 컴파일 다음과 같습니다 나는 다음과 같은 서비스를 만들었습니다
이 오류를 해결할 수 있도록 도와주세요.
을해야'그 때는()의''return'이? 그것이 없다면,'직업'이 어떤 가치를 부여 받았다고 생각합니까? – nnnnnn
.then()는 콜백이 완료 될 때까지 Promise를 반환합니다. 나는() –
의 문서에서 이것을 발견했습니다. 당신이 찾고있는 답을 찾았지만, 업데이트 된 대답은 아직도 투표 할 자격이 있습니까? 그것이 틀렸다면 괜찮아요.하지만 그럴 것 같지 않습니다. 그리고 투표가 실패하면 누군가가 문제를 해결할 수있는 해결책으로 생각할 수 없습니다. 감사! –