API调用后冲突Angular2.map defaultOptions.merge不是中的函数
我尝试通过post方法调用API,但出现以下错误: 这是一个函数。\u defaultOptions.merge不是一个函数… 我检查了一些答案,我试图导入,但没有成功API调用后冲突Angular2.map defaultOptions.merge不是中的函数,angular,angular2-template,angular2-directives,angular2-services,Angular,Angular2 Template,Angular2 Directives,Angular2 Services,我尝试通过post方法调用API,但出现以下错误: 这是一个函数。\u defaultOptions.merge不是一个函数… 我检查了一些答案,我试图导入,但没有成功 导入'rxjs/add/operator/map' 进口“rxjs/rx” 这是我的代码,如果您想尝试一下,请: 图书服务 更新2 我包括了app.component和main 梅因酒店 app.component.ts 任何帮助都会很好。 感谢各位将请求凭证更改为 @Injectable() export class re
- 导入'rxjs/add/operator/map'李>
- 进口“rxjs/rx”李>
感谢各位将
请求凭证
更改为
@Injectable()
export class requestCredentials extends RequestOptions {
constructor() {
let headers = new Headers();
headers.append('X-Requested-With', 'XMLHttpRequest');
super({method: RequestMethod.Get, headers: headers, withCredentials: true});
}
}
(未测试)错误消息是关于
merge
,但您尝试的修复是关于map
。我看不到defaultOptions
或merge
可用于代码中的任何地方。你能提供更多的细节(完整的堆栈跟踪,更多的代码,…)吗?谢谢@GünterZöchbauer,我包括了界面和完整的代码。请记住,post请求使用payload=bookmode添加的代码仍然不包含任何merge
或defaultOptions
。你有堆栈跟踪吗?defaultOptions
可能来自Http
@GünterZöchbauer,我没有使用merge
或defaultOptons
,我在Http.dev.js中找到它的唯一一个。我跟踪了结果,但在调用.map…
时创建了错误。似乎我做错了什么是的,这就是我的假设(我之前的评论)。能否从浏览器控制台提供堆栈跟踪?如何以及在何处提供HTTP_提供程序?它不起作用,似乎“withCredentials:true”不是RequestOptions的参数。这就是错误:{method:RequestMethod;headers:headers;withCredentials:boolean;}类型的ts]参数不能分配给'RequestOptionsArgs'类型的参数。Object literal可能只指定已知的属性,而“RequestOptionsArgs”类型中不存在“withCredentials”。我在这里看到了它,但这似乎是最近添加的,并且尚未包含在RC.1中。这可能会有帮助,谢谢你,伙计,你现在有没有另一个解决方案我可以看看?因为这不是发布,我什么也做不了。只有我在之前的评论中链接到的两个答案。谢谢你,伙计,我感谢你的帮助
import {iBooks} from './books.interface';
import {bookService} from './books.service';
@Component({
selector: 'books-list',
templateUrl: './books.component.html',
providers: [bookService]
})
export class bookComponent implements OnInit {
errorMessage: string;
trips: iBooks[];
_payload: bookMode;
constructor(private _bookService: bookService){
}
ngOnInit(): void {
this._bookService.getInfo(this._payload)
.subscribe(
trips => this.trips = trips,
error => this.errorMessage = <any>error);
}
}
export class bookMode{
Name: string;
Pages: number;
Items: number;
}
export interface iBooks {
Name: string;
Pages: number;
Items: number;
}
import {bootstrap} from 'angular2/platform/browser';
import {AppComponent} from './app.component';
import {provide} from 'angular2/core';
import {ROUTER_PROVIDERS} from 'angular2/router';
import 'rxjs/Rx';
import {HTTP_PROVIDERS, Headers, RequestOptions} from 'angular2/http'; // Required by credetials
class requestCredentials {
headers: Headers = new Headers({
'X-Requested-With': 'XMLHttpRequest'
});
withCredentials: boolean = true;
}
bootstrap(AppComponent, [ROUTER_PROVIDERS, HTTP_PROVIDERS, provide(RequestOptions, {useClass: requestCredentials})]);
import {Component, ElementRef} from 'angular2/core';
import {RouteConfig, ROUTER_DIRECTIVES, RouterLink } from 'angular2/router';
import {HTTP_PROVIDERS} from 'angular2/http';
import 'rxjs/Rx';
import {EmptyComponent} from './myComponent.component'
@Component({
selector: 'my-app',
templateUrl: './myComponent.component.html',
directives: [ROUTER_DIRECTIVES, RouterLink]
})
export class AppComponent {
}
@Injectable()
export class requestCredentials extends RequestOptions {
constructor() {
let headers = new Headers();
headers.append('X-Requested-With', 'XMLHttpRequest');
super({method: RequestMethod.Get, headers: headers, withCredentials: true});
}
}