2017-07-21 67 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 Property'append'在類型'Headers'上不存在

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

如何解決?

+0

把你的代碼'let headers:Headers = new Headers(); headers.append('Content-Type','application/json');'在constructor'或'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'); 
    } 
} 
相關問題