File

src/context-menu/context-menu-selection.service.ts

Index

Properties
Methods

Constructor

constructor()

Methods

selectCheckbox
selectCheckbox(value: any)
Parameters :
Name Type Optional
value any No
Returns : void
selectCheckboxes
selectCheckboxes(value: any[])
Parameters :
Name Type Optional
value any[] No
Returns : void
selectRadio
selectRadio(value: any)
Parameters :
Name Type Optional
value any No
Returns : void

Properties

Public selectionObservable
Type : Observable<any | []>
Private selectionSubject
Default value : new ReplaySubject<any | any[]>(1)
Private value
Type : any[]
Default value : []
import { Injectable } from "@angular/core";
import { Observable, ReplaySubject } from "rxjs";

@Injectable()
export class ContextMenuSelectionService {
	public selectionObservable: Observable<any | any[]>;
	private selectionSubject = new ReplaySubject<any | any[]>(1);
	private value: any[] = [];

	constructor() {
		this.selectionObservable = this.selectionSubject.asObservable();
	}

	selectRadio(value: any) {
		if (!value) {
			return;
		}
		this.selectionSubject.next(value);
		this.value = [value];
	}

	selectCheckbox(value: any) {
		if (!value) {
			return;
		}
		if (this.value.includes(value)) {
			this.value = this.value.filter(v => v !== value);
		} else {
			this.value.push(value);
		}
		this.selectionSubject.next(this.value);
	}

	selectCheckboxes(value: any[]) {
		if (!value) {
			return;
		}
		this.value = value;
		this.selectionSubject.next(value);
	}
}

results matching ""

    No results matching ""