1
일반적인 문제이지만, 필자의 경우 왜 복제되었는지 이해할 수 없습니다. 며칠 만에 답을 찾을 수 없었습니다.SyntaxError : Angular 5 서비스에서 예기치 않은 입력이 있습니다.
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { Response, RequestOptionsArgs, ResponseContentType } from '@angular/http';
import { Http, RequestOptions, Request, RequestMethod, Headers } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import { map } from 'rxjs/operators';
@Injectable()
export class BaseService {
private headers: Headers = new Headers({ 'Content-Type': 'application/json; charset=utf-8', 'Data-Type': 'json' });
constructor(private http: Http, private router: Router,) {
}
public get<T>(url: string, options?: RequestOptionsArgs): Promise<T> {
return this.http.get(url, options)
.toPromise()
.then(response => response.json() as T)
.catch(this.handleError.bind(this));
}
public handleError(error: any) {
if (error.status === 400) {
switch (error.statusText) {
case 'Authentication':
this.router.navigate(['/error/auth']);
break;
default:
return Promise.reject(error);
}
return;
}
return Promise.reject(error.toString());
}
}
방법이라는 기본 방법을 Folowing :
각 서비스의 일부 Folowing
getSearchResultTable(hash: number): Promise<Prices[]> {
const tmp = this.baseService.get<Prices[]>(this.apiUrl + hash);
return tmp;
}
JSON 서버에서 반환 유효합니다. 나는 그것을 온라인 서비스 하나에 점검했다.
그러나 디버그 할 때 Response
에 SyntaxError: Unexpected end of input
오류가 표시됩니다.
호출 스택 :
SyntaxError: Unexpected end of input
at BaseService.get (webpack-internal:///../../../../../src/app/search-module/services/base.service.ts:36:14)
at SearchResultService.getSearchResultTable (webpack-internal:///../../../../../src/app/search-module/services/search-result.service.ts:30:36)
at SearchResultPageComponent.ngOnInit (webpack-internal:///../../../../../src/app/search-module/pages/search-result/search-result.component.ts:24:34)
at checkAndUpdateDirectiveInline (webpack-internal:///../../../core/esm5/core.js:12291:19)
at checkAndUpdateNodeInline (webpack-internal:///../../../core/esm5/core.js:13794:20)
at checkAndUpdateNode (webpack-internal:///../../../core/esm5/core.js:13737:16)
at debugCheckAndUpdateNode (webpack-internal:///../../../core/esm5/core.js:14609:76)
at debugCheckDirectivesFn (webpack-internal:///../../../core/esm5/core.js:14550:13)
at Object.eval [as updateDirectives] (ng:///SearchModule/SearchResultPageComponent_Host.ngfactory.js:9:5)
at Object.debugUpdateDirectives [as updateDirectives] (webpack-internal:///../../../core/esm5/core.js:14535:21)
내가 각도의 최신 버전을 사용하고 있습니다. 각 최신 업데이트에서
감사합니다. 그러나 이것을 제거한다면 결과를'Prices []'에 어떻게 바인딩 할 것인가? – Seva
'.then (응답 => T로 응답) ' –
회귀 오류입니다. '오류 TS2352 : '응답'유형을 'T'유형으로 변환 할 수 없습니다. ' – Seva