Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

243
Visualizações
How to access nested property from ngrx selector Observable?

Initial Data definition and Interface:

export interface IInitialData {
    version: {
        patch?: string;
        Version: string,
        build: number,
    };
}

export const initialStateInitialData = {
    version: {
        build: 0,
        Version: '1',
    },
};

I have the following selectors in the selectors file:

export const selectInitialDataFeature = createFeatureSelector<IInitialData>('initialData');`

export const selectInitialData = createSelector(
    selectInitialDataFeature,
    initialData => {
        return initialData;
    },
);

export const selectInitialDataVersion = createSelector(
    selectInitialData,
    initialData => {
        return initialData.version.Version;
    },
);

Accessing 2nd one from component file:

public version$ = this.store.select(selectInitialDataVersion);

And from template file:

[value]="version$ | async"

This works fine.

However, following returns error "Unresolved variable version"

public initialData$ = this.store.select(selectInitialData);
[value]="initialData$.version.Version | async"`

How do I access the variable version.Version in this manner?

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

<ng-container *ngIf="(initialData$ | async) as myInitialData">
  <my-component [value]="myInitialData.version.Version">
  </my-component>
</ng-container>

You are trying to access the value of your Observable without subscribing it, which in this case, before using the async pipe

Or if you don't want to handle that in your template html, you could do it in your .ts file

ngOnInit() {
  this.store.select(selectInitialData).subscribe(
   (myData) => this.initialData = myData.version.Version; 
  );
}
<
 ...
 ...
 [value]="intialData">
over 4 years ago · Santiago Trujillo Relatório

0

You need to use the async pipe directly after the observable, then then access the properties:

[value]="(initialData$ | async).version.Version"
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda