0

I have angular component where I use providers

Here is code

    @Component({
  selector: 'app-service-desk-ticket-main-data',
  templateUrl: './service-desk-ticket-main-data.component.html',
  styleUrls: ['./service-desk-ticket-main-data.component.scss'],
  providers: [
    UserLinkStatisticService,
    { provide: OPEN_PROFILE_TRACKING_CATEGORY_TOKEN, useValue: STATISTIC.CATEGORY.SERVICE_DESK },
    { provide: OPEN_PROFILE_TRACKING_LOCATION_TOKEN, useValue: STATISTIC.LOCATION.SD_TICKETS_PAGE },
  ],
})

in component code I want to change value of OPEN_PROFILE_TRACKING_LOCATION_TOKEN related on @Input value

Here is pseudo code of Component

  export class ServiceDeskTicketMainDataComponent implements OnInit {
  @Input()
  public model: ServiceDeskTicket;

  @Input()
  public isPopup = false;

  @Output() subscriptionChanged = new EventEmitter<void>();

  public readonly unsubscribeTitle =
    'If you unsubscribe, you will only receive notifications when your name is mentioned on this ticket';

  public location: string;

  constructor(
    private serviceDeskService: ServiceDeskService,
    private popupService: PopupService,
    private preloader: PreloaderService,
    private cdr: ChangeDetectorRef,
    private alertService: AlertService,
    private statistic: ServiceDeskStatisticService,
  ) {}

  public ngOnInit(): void {
    this.location = this.isPopup ? STATISTIC.LOCATION.SD_TICKETS_PAGE_POPUP : STATISTIC.LOCATION.SD_TICKETS_PAGE;
  }
}

Logic is in OnInit. I need same logic, but for provider useValue

Eugene Sukh
  • 2,357
  • 4
  • 42
  • 86
  • I'm not sure I understand what problem you are trying to solve. You want to change one of your providers dynamically? – Chris Barr Apr 21 '23 at 11:58
  • yes, in OnInit @FiniteLooper – Eugene Sukh Apr 21 '23 at 11:58
  • I do not believe it is possible to dynamically change the providers like that. That happens internally inside Angular before any of your code is called and I do not believe it can be changed after the fact since that would mess with Angular in unpredictable ways. Why do you need to do this? If it's just for display in the component you could just choose which value to display like you are already doing. – Chris Barr Apr 21 '23 at 12:12
  • I need to change location that will be passed to service, I really think Angular has option to change value @FiniteLooper – Eugene Sukh Apr 21 '23 at 12:18
  • Hmm, well it's not something I'm very familar with. Does something like [this question](https://stackoverflow.com/questions/54209879/how-to-set-config-or-usevalue-for-imported-modules-from-a-component) help? – Chris Barr Apr 21 '23 at 12:24

0 Answers0