import { Subscription } from 'rxjs/Subscription';
...
private orderSubscription: Subscription;
ngOnInit() {
this.orderSubscription = this.orderService.orders.subscribe()
};
ngOnDestroy() {
this.orderSubscription.unsubscribe();
}
export class OrderService {
private _orders: BehaviorSubject<OrderViewModel[]> = new BehaviorSubject([]);
public readonly orders: Observable<OrderViewModel[]> = this._orders.asObservable();
constructor(private httpClient: HttpClient) {
this.fetch();
}
fetch() {
this.httpClient.get('data').subscribe(result => {
this._orders.next(result);
});
}
}
export class MainComponent implements OnInit {
orderData: OrderViewModel[];
constructor(private orderService: OrderService) {
this.orderService.orders.subscribe((orderData) => {
this.orderData = orderData;
})
}
public refresh() {
this.orderService.fetch();
}
}
private _orders: BehaviorSubject<OrderViewModel[]> = new BehaviorSubject([]);
public readonly orders: Observable<OrderViewModel[]> = this._orders.asObservable();
Функция _intersection принимает на вход два массива чисел. И возвращает два массива чисел, в которых числа сгруппированы в подмассивы по такому-то правилу.
<base href="/ru">