Skip to content

Valuing @Input() properties of scene component #4

Answered by nartc
cmalosse asked this question in Q&A
Discussion options

You must be logged in to vote

@cmalosse You'd need to use an InjectionToken or a Service

  1. If the selectId is set once, use regular number
  2. If the selectId can change, use Observable<number>
export const SELECTED_ID = new InjectionToken<number>('selectedId');
// can also be an Observable: export const SELECTED_ID = new InjectionToken<Observable<number>>('selectedId$');

@Component({/* */)
export class PreviewScene {
    readonly selectedId = inject(SELECTED_ID);
    // or use constructor(@Inject(SELECTED_ID) private readonly selectedId: number) {}
}

// provide the token with: {provide: SELECTED_ID, useValue/useFactory etc...}

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@nartc
Comment options

@cmalosse
Comment options

@nartc
Comment options

@cmalosse
Comment options

Answer selected by nartc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants