与观察到的
问题描述:
的Http REST API的数据让我解释一下我的项目结构:
从服务器获取数据:我做了一个服务的AuthenticationService
我叫这项服务在HTML文件中列出的数据的组件&:(ProductComponent & ProductComponent Html文件)
我有一个头文件夹目录,其中包含一个组件&HTML文件,现在我在标题中添加了产品搜索,此标题是网站主标题,并且对所有网站均可见。
现在我想通过observable使产品列表异步。 服务文件代码:与观察到的
getProductList(check:any) {
let time = new Date();
return this.http.post('/api/productslist.json?' + time.getTime(), check)
.map((response: Response) => {
let result = response.json();
return result;
});
}
组件代码:
export class ProductlistComponent implements OnInit {
result: Result[] =[];
filtercheck = {};
constructor(private authenticationService: AuthenticationService) {
this.authenticationService.getProductList(this.filtercheck)
.subscribe(result => {
this.result = result.result.list;
},err => {
}
);
}
}
当我从任何组件调用这个服务,我需要那么产品列表需要自动更新。就像我在标题搜索框中输入的那样,产品列表需要自动更新 e。
我试着通过observable订阅,但没有成功。当我将HTTP数据设置为可观察时,我感到困惑。如果我设置了可观察的服务中成功部分,那么它并不反映结果。 请帮忙
例如: : URL:https://www.flipkart.com/ 像头像中的某人类型,然后按搜索按钮,然后产品列表自动更新。我需要这种类型的功能
答
从服务器获取数据:I要获取或发布?
服务
如果是后
getProductList(check:any) {
let time = new Date();
return this.http.get('/api/productslist.json?' + time.getTime(), JSON.stringify(check) // stringfy the object
.map((response: Response) => response.json());
}
组件
this.authenticationService.getProductList(this.filtercheck).subscribe(result => {
this.result = result.result.list;
}
更新
const eventStream = Observable.fromEvent(elementRef.nativeElement, 'keyup')
.map(() => this.inputValue)
.debounceTime(this.delay)
.distinctUntilChanged();
我需要从任何组件产品列表中调用此服务时需要自动更新。像我在标题搜索框中键入然后产品列表需要授权更新 –
你没有做一个字符串的帖子对象,请检查答案 –
不,这是不是问题,我发送'检查'在JSON-stringify –