import { Http, Headers } from '@angular/http';
export class LoginComponent implements OnInit {
let headers: Headers = new Headers();
headers.append('Content-Type','application/json');}
上述代码出现以下错误。
'append'错误:'Headers'类型中不存在属性'append'。
如何解决?
答案 0 :(得分: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');
}
}