-1

I'm very new to Angular 4. I have 4 input texts say-name, address, zipcode, and country which is a drop down list.

There is a button which is disabled when there is no name, country and address. For few countries, zip code is mandatory (this check is done using API call which gives us true or false value, if true then zip code is required). For the countries that return true, button must be disabled for name, country, address, and zip code.

Please help.

malioboro
  • 3,097
  • 4
  • 35
  • 55
Prasuram
  • 1
  • 1
  • 2

2 Answers2

0

You can add [disabled]="boolean" to your html element to make it conditionally disabled.

for example:

<button [disabled]="formNotComplete">submit form</button>

EDIT: like Dhananjai Pai recommended indeed. When using angular forms you can add validators. Then you can enable the button when your complete form is valid.

Ken Bostoen
  • 134
  • 8
0

If you are using Angular FormsModule or ReactiveFormsModule, you can set the validations accordingly and auto-magically get the valid property with the ngForm variable if all the form elements are valid. You can directly bind this to the [disabled] property in the html template and get it functional.

Dhananjai Pai
  • 5,914
  • 1
  • 10
  • 25