angular - TypeError: this.syncService.getShops(...).valueChanges 不是函数
问题描述
收到“TypeError:this.syncService.getShops(...).valueChanges 不是函数”错误,但我似乎无法弄清楚原因。它与我的getShops()
功能有关吗?getShops
返回一个商店对象数组。据我所知,这应该不是问题。Angular 新手,我正试图让我的离子搜索栏在商店列表上工作。
打字稿
import { Component, OnInit, Input, ViewChild } from '@angular/core';
import { ToolbarTitleService } from '../Services/toolbar-title.service';
import { IonSearchbar, PopoverController } from '@ionic/angular';
import { PopoverComponent } from '../popover/popover.component';
import { SyncServiceService } from '../Services/sync-service.service';
import { UserService } from '../Services/user.service';
import { first } from 'rxjs/operators';
@Component({
selector: 'app-locaties',
templateUrl: './locaties.component.html',
styleUrls: ['./locaties.component.css'],
})
export class LocatiesComponent implements OnInit {
public locations: any[] = [];
user;
public locationsBackup: any[] = [];
constructor(
private toolbarTitle: ToolbarTitleService,
public popoverController: PopoverController,
private syncService: SyncServiceService,
private userService: UserService
) {}
async ngOnInit() {
this.toolbarTitle.setToolbarTitle('Locaties');
this.user = await this.userService.getUser();
// Haalt alle shops van de gebruiker op en zet ze in locations
this.locations = await this.syncService.getShops(this.user);
this.locations = await this.initializeItems();
}
// Popover
async presentPopover(ev: any, Contact: any) {
const popover = await this.popoverController.create({
component: PopoverComponent,
componentProps: {
phones: Contact.Phones[0].Number,
email: Contact.Email,
street: Contact.Addresses[0].Street1,
city: Contact.Addresses[0].City,
},
event: ev,
translucent: true,
});
return await popover.present();
}
// Search
async initializeItems(): Promise<any> {
this.locations = await this.syncService
.getShops(this.user)
.valueChanges()
.pipe(first())
.toPromise();
this.locationsBackup = this.locations;
return this.locations;
}
// Filter
async filterList(evt) {
this.locations = this.locationsBackup;
const searchTerm = evt.srcElement.value;
if (!searchTerm) {
return;
}
this.locations = this.locations.filter((currentLocation) => {
if (currentLocation.Name && searchTerm) {
return (
currentLocation.Name.toLowerCase().indexOf(searchTerm.toLowerCase()) >
-1
);
}
});
}
}
解决方案
推荐阅读
- swiftui - SwiftUI:当 CLAuthorizationStatus 更改时在视图上运行代码
- c# - 项目输出类型未更改为控制台应用程序,控制台窗口未在 WinForms 中显示
- algorithm - 送餐应用使用什么算法对附近的订单进行分组?
- text - 在STM32 F4内部闪存中存储和写入文本文件
- c# - MondoDB:查找文档匹配列表对象的所有字段
- c# - WPF 在后台工作完成后自动关闭对话框
- amazon-web-services - AWS CDK Java - 模板格式错误:映射元素计数 0 应大于 0
- java - del 函数在这个程序中是如何执行的?del 函数在这个程序中是如何执行的?del 函数在这个程序中是如何执行的?
- logging - 将日志消息从 datadog 发送到松弛通道
- sql - SQL 错误 [937] [42000]: ORA-00937: not a single-group group function