Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用Angular 5中的服务为Http请求设置头_Javascript_Angular_Typescript_Angular5 - Fatal编程技术网

Javascript 使用Angular 5中的服务为Http请求设置头

Javascript 使用Angular 5中的服务为Http请求设置头,javascript,angular,typescript,angular5,Javascript,Angular,Typescript,Angular5,我正在尝试从该服务发出get请求,如下所示: 从'@angular/common/http'导入{HttpClient,HttpHeaders}; 从“@angular/core”导入{Injectable}; //从“rxjs/observable/of”导入{of}; @可注射() 导出类AccountsService{ 构造函数(公共http:HttpClient){} 公共httpOptions={ 标题:新的HttpHeaders({ “内容类型”:“应用程序/json”, “授权”

我正在尝试从该服务发出get请求,如下所示:

从'@angular/common/http'导入{HttpClient,HttpHeaders};
从“@angular/core”导入{Injectable};
//从“rxjs/observable/of”导入{of};
@可注射()
导出类AccountsService{
构造函数(公共http:HttpClient){}
公共httpOptions={
标题:新的HttpHeaders({
“内容类型”:“应用程序/json”,
“授权”:“基本”+btoa('abc:xys')
})
}
私人帐户http://semsem.talaween.net/semsem/api/v1/users/';
getAccounts(){
返回此.http.get('http://semsem.talaween.net/semsem/api/v1/users/,此为.httpOptions);
//log('我们到了');
}

}
您需要检查或将CORS设置添加到后端。