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

115
Vistas
What happens when angular HostBinding is used along with directive assignment?

I've written a directive in angular that disables or enables a button after validating an object. But the button also has some other simple validation requirements which are directly supplied to the "disabled" directive as value. Example code html:

<button (click)="onSave()"
    [disabled]="validation1() || !validation2()"
    [validProperty]="myObject.property">Save</button>

This is my directive:

import { Directive, Input, OnChanges, HostBinding } from '@angular/core';
import { SomeType } from '../../types/data.types';

@Directive({
    selector: '[validProperty]'
})
export class ValidateDirective implements OnChanges {

    @HostBinding('disabled') disabled: boolean;
    @Input('validProperty') property: SomeType[];

    constructor() {
    }

    ngOnChanges() {
        this.disabled = !this.validateProperty(this.property);
    }

    private validateProperty(property: SomeType[]): boolean {
        return false;
    }
}

Currently, my button only considers validations submitted to [disabled] and not my directive, eventhough control reaches my directive(I've used devtools breakpoints to check). How do i make it consider both [disabled] validations and my directive hostbinding? Kindof like an or operator. Thanks for help in advance :)

about 4 years ago · Juan Pablo Isaza
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