Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

176
Vistas
Referencing an enum in an Angular component before using it

I have the following component:

@Component({
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {
  // Must reference the enum to be able to use types later
  enumModalContentType = EnumModalContentType;
  // Changes according to button clicks to point to the right component to show in modal
  modalContentType: EnumModalContentType;
}
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" (click)="modalContentType = enumModalContentType.EnumValue" data-toggle="modal" data-target="#myModal">
	Launch demo modal
</button>

<app-modal [contentType]="modalContentType"></app-modal>

Which works perfectly well. My question is: why is it that we're obliged to reference EnumModalContentType in order to be able to use it in the HTML later? Why can't we just use it as a type directly?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

It all comes down to scope. It is the same reason why if you are building AOT, you can't have private variables used in your templates. There must be a local public variable in the same scope as your template. At build time, everything is logically separated and scoped, and without a local variable there is nothing for the template to bind to.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda