File

libs/d3/src/lib/helper/d3-graph-id.service.ts

Description

Service to hold the corresponding graph id

Index

Properties
Methods

Methods

Public getId
getId()

Returns the graph id in an observable

Returns : Observable<string>

Observable of the graph id

Public setId
setId(id: string)

Sets the graph id

Parameters :
Name Type Optional Description
id string No

the graph id

Returns : void

Properties

Private id
Type : string
Private subject
Type : Subject<string>
Default value : new Subject()
import { Injectable } from '@angular/core';
import { Observable, of, Subject } from 'rxjs';

/**
 * Service to hold the corresponding graph id
 */
@Injectable()
export class D3GraphId {

  private id: string;

  private subject: Subject<string> = new Subject();

  /**
   * Returns the graph id in an observable
   *
   * @returns Observable of the graph id
   */
  public getId(): Observable<string> {
    return this.id ? of(this.id) : this.subject;
  }

  /**
   * Sets the graph id
   *
   * @param id the graph id
   */
  public setId(id: string) {
    this.id = id;
    this.subject.next(id);
    this.subject.complete();
  }
}

result-matching ""

    No results matching ""