export class Model{
code:string;
desc: string;
}
export class component {
observable$= Observable<Model[]>;
}
我有可观察的$类型的Model从服务中使用。现在可观察的$具有以下值
[{code:1 desc: 'green'} {code:2, desc:'green'}, {code:3, desc:'yellow'}]
如何将可观察对象过滤为仅包含code = 1和code = 2。我尝试了以下方法,但无法正常工作。
observable$.pipe(
map(res => res.filter(item => item.code ==1 && item.code==2))
);
预期输出
[{code:1 desc: 'green'} {code:2, desc:'green'}]