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

313
Vistas
cómo crear un formato de directiva personalizado seleccione y escuche el evento de cambio

En mi proyecto, es necesario usar nativeelement.value de nativeelement.value debido a algunos errores de solo lectura. solo mi directiva

 export class DeliveryAcrossDirective { @Input('key') key: string; @Input('component') component: string; constructor( private store: Store, private elementRef: ElementRef<HTMLInputElement> ) { this.key = ''; this.component = ''; } @HostListener('change') onChange() { console.log('noticed something'); this.store.dispatch<IAction<IAdjust>>({ type: RDX_DELIVERY_ACROSS_ADJUST, payload: { key: this.key, value: this.elementRef.nativeElement.value }, component: this.component }) } }

no captura el evento de cambio de mi mat select

 <mat-form-field class="full-width" [@transformRightLeftStateTrigger]="stateDown | async"> <mat-label> {{ country | async }} </mat-label> <mat-select [formControl]="countryFormControl" appDeliveryAcross [key]="'iso'" [component]="'delivery-across'" > <mat-option *ngFor="let language of (languages | async)" [value]="language.value"> {{ language.country }} </mat-option> </mat-select> </mat-form-field>

mientras que las entradas clásicas sí

 <mat-form-field class="full-width" [@transformRightLeftStateTrigger]="stateDown | async"> <input matInput [formControl]="minFormControl" [errorStateMatcher]="errorStateMatcher" placeholder="Minimaal" appDeliveryAcross [key]="'min'" [component]="'delivery-across'" type="number"> </mat-form-field>

¿Alguien sabe una forma de capturar el evento de cambio de un tapete seleccionado con una directiva?

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

0

No estoy seguro de qué versión de Angular Material está utilizando, pero probablemente el evento de change simple no existe para mat-select https://stackoverflow.com/a/50223943/9602452

Parece que ha modificado su directiva para mat-select s

over 4 years ago · Santiago Trujillo Denunciar

0

Para detectar cambios de mat-select , no necesita HostListener , solo suscríbase a selectionChange of MatSelect

 export class DeliveryAcrossDirective implements OnInit, OnDestroy { selectionSub: Subscription; constructor( private host: MatSelect ) { } ngOnInit(): void { this.selectionSub = this.host.selectionChange.subscribe(option => { console.log(option); // Do something }); } ngOnDestroy(): void { this.selectionSub?.unsubscribe(); } }
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