Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

113
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!