의 특성 'GET'을 읽을 수 없습니다 나는 angular2 관찰을 통해 웹 서비스를 얻기 위해 노력하지만, 나는 app.module.ts에서 HttpModule의 수입 오류는 Angular2가 관찰 오류 형식 오류를 얻을 :
ERROR TypeError: Cannot read property 'get' of undefined
전나무가있다. currencyService 공급자가 있습니다. 이것은 내 첫 번째 시도이다
import { Component, OnInit } from '@angular/core';
import { ICurrency } from './currency';
import { CurrencyService } from './currency.service';
@Component({
selector: 'app-currency',
templateUrl: './template.html',
styles: []
})
export class CurrencyComponent implements OnInit {
currency: array<ICurrency>;
error: string;
constructor(private _currencyService: CurrencyService) { }
ngOnInit(){
this.getCurrency();
}
getCurrency(){
this._currencyService
.getCurrency()
.subscribe(
currency => this.currency = currency,
err => this.error = <any>error
)
}
}
: 최종 currency.component.ts에서
import { Injectable } from '@angular/core';
import { Http, Response } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
import { ICurrency } from './currency';
@Injectable()
export class CurrencyService {
currency:Array<ICurrency>;
constructor(private _http: Http);
getCurrency(): Observable<ICurrency[]>{
return this._http
.get('https://api.fixer.io/latest?base=PLN&symbols=EUR,USD,GBP,CZK,CHF,RUB')
.map(res: Response => <ICurrency[]>res.json());
};
}
: 다음 나는 내 currency.service.ts을 modyficated currency.ts (인터페이스) 다음을 createed Observable을 사용하고, Angular2에서 상당히 새로워졌습니다. 나는 어떤 tutoria를 기반으로 몇 가지를보고 yt를 읽었지만, 나는 심지어 어디에 실수가 될지 모른다.
서비스의 생성자 이후에 중괄호가 누락되었습니다. –
대단히 감사합니다. 내 바보 같은 실수였습니다. 나는지도 부분에있는 동일한 파일에서 실수를했다 – Eva