【发布时间】:2018-11-12 23:54:07
【问题描述】:
我正在尝试确定 observable 是否包含字符串。这个问题是双重的。如何将结果映射回一个对象,然后在我拥有该对象后确定它是否包含特定的 orderId。
我用这个例子没有运气: How to check if a RxJS Observable contains a string in Angular2?
我有这项服务:
public getOrders(): Observable<OrderModel[]> {
return this.http
.get(this.apiURL)
.map(response => response.json() as OrderModel[]);
}
我的组件有这个:
private verifyPaidOrder(): Observable<OrderModel[]> {
//this works fine and gives me back everything.
// this.orderService.getOrders().subscribe(
// (response => this.allOrders = response),
// (err) => { this.handleError(err); });
// now, how do I determine if orderId exists?
// Property 'orderId' does not exist on type 'OrderModel[]
this.orderService.getOrders().map(x => x.orderId) <-- Can't do this!!
.first(roles => roles.indexOf(name) !== -1, undefined, false)
.map(val => !!val);
...
}
我的模型是:
export class OrderModel {
constructor(
public orderId: number,
public firstName: string,
public lastName: string,
public emailAddress: string,
public organizationName: string,
public city: string,
public state: string,
public zipCode: number,
) { }
}
【问题讨论】:
标签: angular typescript