ERROR TypeError: subscribe is not a function
ERROR TypeError: subscribe is not a function
我正在尝试根据某个元素从数组中获取值,然后获取完全匹配的元素。但不知何故,我在这个函数 getProduct(name1: string) 中遇到了这个错误,我已经导入了地图。帮助将不胜感激。
this.searchProduct(...).subscribe 不是函数
products: Product[] = [];
product: Product;
searchProduct(name2: string): Observable<Product[]> {
var config = {
headers: {
'Content-Type': 'application/json'
}
};
const ans = name2;
let obj = { name_product: ans }
let body = JSON.stringify(obj);
let header = new HttpHeaders();
header = header.append('Content-Type','application/json');
return this.httpClient.post('postRestService', body, config).subscribe(res => {
this.products = res;
console.log(this.products);
})
}
getProduct(name1: string): Observable<Product> {
return this.searchProduct(name1).subscribe(products =>
products.find(product => product.name1 == name1));
}
http 服务从 angular 2 更改为 angular 4。在 angular 4 中,您不需要地图:
products: Product[] = [];
product: Product;
searchProduct(name2: string): Observable<Product[]> {
var config = {
headers: {
'Content-Type': 'application/json'
}
};
const ans = name2;
let obj = { name_product: ans }
let body = JSON.stringify(obj);
let header = new HttpHeaders();
header = header.append('Content-Type','application/json');
this.http.post('postRestService', body, config).subscribe(res => {
this.products = res;
console.log(this.products);
})
}
getProduct(name1: string): Observable<Product> {
return this.searchProduct(name1).subscribe(products => products.find(product => product.name1 == name1));
}
我正在尝试根据某个元素从数组中获取值,然后获取完全匹配的元素。但不知何故,我在这个函数 getProduct(name1: string) 中遇到了这个错误,我已经导入了地图。帮助将不胜感激。 this.searchProduct(...).subscribe 不是函数
products: Product[] = [];
product: Product;
searchProduct(name2: string): Observable<Product[]> {
var config = {
headers: {
'Content-Type': 'application/json'
}
};
const ans = name2;
let obj = { name_product: ans }
let body = JSON.stringify(obj);
let header = new HttpHeaders();
header = header.append('Content-Type','application/json');
return this.httpClient.post('postRestService', body, config).subscribe(res => {
this.products = res;
console.log(this.products);
})
}
getProduct(name1: string): Observable<Product> {
return this.searchProduct(name1).subscribe(products =>
products.find(product => product.name1 == name1));
}
http 服务从 angular 2 更改为 angular 4。在 angular 4 中,您不需要地图:
products: Product[] = [];
product: Product;
searchProduct(name2: string): Observable<Product[]> {
var config = {
headers: {
'Content-Type': 'application/json'
}
};
const ans = name2;
let obj = { name_product: ans }
let body = JSON.stringify(obj);
let header = new HttpHeaders();
header = header.append('Content-Type','application/json');
this.http.post('postRestService', body, config).subscribe(res => {
this.products = res;
console.log(this.products);
})
}
getProduct(name1: string): Observable<Product> {
return this.searchProduct(name1).subscribe(products => products.find(product => product.name1 == name1));
}