2017-07-21 5 views
0
import { Http, Headers } from '@angular/http'; 
    export class LoginComponent implements OnInit { 
     let headers: Headers = new Headers(); 
     headers.append('Content-Type','application/json');} 

上記のコードで次のエラーが発生します。angular2プロパティ 'append'が 'ヘッダー'タイプに存在しません

'append' error: Property 'append' does not exist on type 'Headers'.

どうすれば解決できますか?

+0

あなたのコードを置く:let headers:Headers = new Headers(); headers.append( 'Content-Type'、 'application/json'); 'コンストラクタ'または 'ngOnInit()'の中にあります。 –

答えて

1

代わりにこれを試してください。

import {OnInit} from '@angular/core'; 
import {Headers, Http} from '@angular/http'; 

export class LoginComponent implements OnInit{ 

    public headers: Headers; 

    constructor(private http: Http) { 
    this.headers = new Headers(); 
    this.headers.append('Content-Type', 'application/json'); 
    this.headers.append('Accept', 'application/json'); 
    } 
} 
関連する問題