Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 如何在不订阅可观察数组的情况下从可观察数组中删除多个元素_Angular_Rxjs - Fatal编程技术网

Angular 如何在不订阅可观察数组的情况下从可观察数组中删除多个元素

Angular 如何在不订阅可观察数组的情况下从可观察数组中删除多个元素,angular,rxjs,Angular,Rxjs,在angular 4应用程序中,我遇到了一个场景,即从包含自定义类型的可观察数组中删除几个元素。这里我有另一个可观察的元素数组要删除。是否有一种方法可以从一个可观测数组中移除另一个可观测数组中的元素,而无需订阅它们 例如,假设我有allCustomers和orderedCustomers的可观察数组 如何找到没有订购任何东西的客户。(所有客户-orderedCustomers=?) 谢谢。您必须使用过滤管才能做到这一点 更多信息请点击此处: 我想这就是你想要的: import {combineL

在angular 4应用程序中,我遇到了一个场景,即从包含自定义类型的可观察数组中删除几个元素。这里我有另一个可观察的元素数组要删除。是否有一种方法可以从一个可观测数组中移除另一个可观测数组中的元素,而无需订阅它们

例如,假设我有allCustomersorderedCustomers的可观察数组

如何找到没有订购任何东西的客户。(所有客户-orderedCustomers=?)


谢谢。

您必须使用过滤管才能做到这一点

更多信息请点击此处:

我想这就是你想要的:

import {combineLatest} from 'rxjs/observable/combineLatest'; // import for rxjs 5+

// these are your existing Observables...
const allCustomers$: Observable<Customer[]>;
const orderedCustomers$: Observable <Customer[]>;

// this will be an Observable of customers with no order
const customersWithNoOrders$: Observable<Customer[]> =
  combineLatest(
    allCustomers$,
    orderedCustomers$,
    (allCustomers, orderedCustomers) => {
      return allCustomers.filter(customer => !orderedCustomers.includes(customer));
    }
  );
从'rxjs/observable/combineLatest'导入{combinelateest};//rxjs 5的导入+
//这些是你现有的观测值。。。
const allCustomers$:可观察的;
const orderedCustomers$:可见;
//这将是一个可观察到的没有订单的客户
const customers with noorders$:可观察=
组合测试(
所有客户$,
订购客户$,
(所有客户、订购客户)=>{
返回allCustomers.filter(customer=>!orderedCustomers.includes(customer));
}
);

您不需要将您的观察对象转换为主题。我将更新我的答案以使用可观测数据…亲爱的米勒,谢谢你的支持,小调整成功了。const customers with noorders$=combineTest(allCustomers$,orderedCustomers$,(allCustomers,orderedCustomers)=>{return allCustomers.filter(customer=>!orderedCustomers.includes(customer));});
import {combineLatest} from 'rxjs/observable/combineLatest'; // import for rxjs 5+

// these are your existing Observables...
const allCustomers$: Observable<Customer[]>;
const orderedCustomers$: Observable <Customer[]>;

// this will be an Observable of customers with no order
const customersWithNoOrders$: Observable<Customer[]> =
  combineLatest(
    allCustomers$,
    orderedCustomers$,
    (allCustomers, orderedCustomers) => {
      return allCustomers.filter(customer => !orderedCustomers.includes(customer));
    }
  );