angular - Simple state service unwanted complexity -
i try make simple service manage single state in application: visibility of loader.
the changes emitted components , main layout component subscribe watch boolean change. it's handled simple ngif.
here code:
import { injectable } '@angular/core'; import { observable } 'rxjs/rx'; import { subject } 'rxjs/subject'; @injectable() export class apploaderservice { private isloadervisible = new subject<boolean>(); changeloaderstate = this.isloadervisible.asobservable(); emitchange(state: any) { this.isloadervisible.next(state); } } is method creating simple service introducing complexity simple toggler?
are use of subject or behaviorsubject relevant in case? found information necessity use them when want emit such changes or set default value @ service init (behaviorsubject).
but maybe simple observable sufficient here, how deal value change emit?
if thing serving simple *ngif, see no use subject , observable. can use simple boolean value property of service. maybe getter , setter, wouldn't make complex observables if have no dependencies have react on change of visibility.
Comments
Post a Comment