Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import {OnDestroy} from "@angular/core";
- import {Subscription} from "rxjs/Rx";
- export class SubscriptionsRemovingComponent implements OnDestroy{
- private subscriptions: Subscription[] = [];
- ngOnDestroy():void {
- this.clearSubscriptions();
- }
- public clearSubscriptions() {
- this.subscriptions.forEach((subscription: Subscription) => {
- subscription.unsubscribe();
- });
- }
- public addSubscription(subscription: Subscription) {
- this.subscriptions.push(subscription);
- }
- }
- class SelectableGroupList extends SubscriptionsRemovingComponent implements OnDestroy {
- private groups:Group[] = [];
- private searchResults: Group[] = [];
- @Output() groupsSelected: EventEmitter<Group[]> = new EventEmitter<Group[]>();
- @Output() backAction = new EventEmitter<any>();
- @Input() selectedGroups: Array<Group> = [];
- constructor(private groupsService: GroupsService,
- private searchService: SearchService) {
- super();
- this.groupsService.getGroups();
- this.setSubscriptions();
- }
- private setSubscriptions() {
- super.addSubscription(
- this.groupsService.selectedGroupsChanged
- .subscribe((selectedGroups:Group[]) => {
- this.groupsSelected.emit(selectedGroups);
- super.clearSubscriptions();
- })
- );
- super.addSubscription(
- this.groupsService.groupsChanged
- .subscribe((groups:Group[]) => {
- this.groups = this.excludeSelectedGroups(groups);
- this.searchResults = this.groups;
- super.clearSubscriptions();
- })
- );
- }
- ngOnDestroy() {
- super.ngOnDestroy();
- this.groupsService.resetSelectedGroups();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement