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

275
Visualizações
Angular: ngIf doesn't recognize enum type

this *ngIf:

<div *ngIf="type === FilterType.DateRangeFilter">
    ...
</div>

results in the error

error TS2339: Property 'FilterType' does not exist on type 'FilterComponent

even though the enum type FilterType is imported into the component:

import { FilterType } from '../filter-collection/filter-collection.component'

@Component({
  selector: 'app-filter',
  templateUrl: './filter.component.html',
  styleUrls: ['./filter.component.css']
})
export class FilterComponent {

  constructor(private type : FilterType) {
  }

  ngOnInit(): void {

  }

}

from here:

export enum FilterType {
  DateRangeFilter, SensorSelectFilter
}

Any ideas why this wouldn't work?

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

0

Your HTML template doesnt have access to variables declared outside of your component. To resolve this, assign the enum to a variable within your component's scope

import { FilterType } from '../filter-collection/filter-collection.component'

@Component({
  selector: 'app-filter',
  templateUrl: './filter.component.html',
  styleUrls: ['./filter.component.css']
})
export class FilterComponent {

  constructor(private type : FilterType) {
  }

  ngOnInit(): void {

  }
  
  filterType = FilterType

}

and then in your template

<div *ngIf="type === filterType.DateRangeFilter">
    ...
</div>

over 4 years ago · Santiago Trujillo Relatório

0

the property type is used in the FilterComponent as private, to be able to use it change it to public or create a new one in FilterComponent and assign it from the constructor

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