2017-04-27 15 views
1

私はこのエラーが発生しており、私は新しいを2番にしていますので、問題を解決する方法は100%ではありません。いくつかのダミーデータを含むjavascriptオブジェクトを返す。しかし、私の "this.onGet()"関数は、指定されたパラメータが呼び出しターゲットのシグネチャと一致しないため、なぜ私がその理由を理解できないように見えるかを伝えています。 (基本的に私はAPIからの情報とORDERINFO配列を移入しようとしているので、私は、複数のページを渡ってそれを使用することができます)

すべてのヘルプ感謝:)"指定されたパラメータがコールターゲットのシグネチャと一致しません。 APIからの情報を収集するためにgetを使用しています

App.component.ts

import { Component, OnInit } from '@angular/core'; 
import { DetailsService } from './details.service'; 

@Component({ 
    selector: 'app-root', 
    templateUrl: './app.component.html', 
    styleUrls: ['./app.component.css'], 
    providers: [DetailsService] 
}) 

export class AppComponent implements OnInit { 
    orderInfo = [ 
     { 
      name: 'Test' 
     } 
    ]; 
    constructor(private detailsService: DetailsService) { 
    } 

    ngOnInit() { 
     this.onGet(); 
    } 

    onGet(name: string) { 
     this.detailsService.getDetails() 
      .subscribe(
       (orderData: any[]) => { 
        this.orderInfo.push({ 
         name: name 
        }); 
        console.log(orderData); 
       } 
      ); 
    } 
} 

details.service.ts

import {Injectable} from '@angular/core'; 
import { Http, Response } from '@angular/http'; 
import 'rxjs/Rx'; 

@Injectable() 
export class DetailsService { 
    constructor(private http: Http) {} 
    getDetails() { 
     return this.http.get('http://swapi.co/api/people/1/?format=json', '') 
      .map(
       (response: Response) => { 
        const orderData = response.json(); 
        return orderData; 
       } 
     ); 

    } 
} 

答えて

1

署名HTTP GETの方法は、あなたが上記のように、あなたの

あなたのメソッドのシグネチャとしてある
ngOnInit() { 
     this.onGet(); //////////nothing passed 
    } 

onGet(name:string)あなたが合格されていないものの中に余分な文字列パラメータに

getDetails() { 
     ///////////////removed below single quotes 
     return this.http.get('http://swapi.co/api/people/1/?format=json') 
      .map(
       (response: Response) => { 
        const orderData = response.json(); 
        return orderData; 
       } 
     ); 

ルックを渡している

get(url: string, options?: RequestOptionsArgs) : Observable<Response> 

です

+0

私はこれをやっていましたが、それは問題を引き起こしているようではありませんでした –

0

あなたのOnGet関数では、文字列パラメータが必要ですngOnInitから呼び出し中に供給されます。

関連する問題