0

I am trying to enable buttonA if buttonB is not disabled (of course there are other conditions not relevant to question). I need to determine in my typescript whether buttonB is disabled. Obviously you can't use this.buttonB.nativeElement.disabled == true .... I just put it in as a placeholder. I am using Angular 2.

@ViewChild('buttonB') buttonB;

if (this.buttonB.nativeElement.disabled == true){
  console.log('Button B is enabled');
} else console.log('Button is disabled');
1
  • Can you provide the html of the button block? Commented Mar 28, 2019 at 4:17

1 Answer 1

1

Here is how you can do it.

First, you use Document.querySelector() (Or document.getElementById(), getElementsByTagName(), etc) to retrieve the button Element (lets assume it has a class of buttonA). Next, you can simply access its attributes and check its values.

If you want to check its disabled attributes, you can simply do check for the value in button['disabled'].

const button = document.querySelector('.buttonA');
console.log(button['disabled']) //prints true or false
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.