The workings of this directive are illustrated in the following 3 scenarios. In each scenario, after the user initially presses ‘save’, the directive makes a call to the address validation service, injects appropriate html (if needed), waits for a user response, and updates the address fields accordingly.
Run the Demo
View the Source Code
The three scenarios this directive handles:
- User enters an invalid address and the service returns a suggested address
- User enters a invalid address and the service doesn’t return a suggested address
- User enters a valid address
Case 1
Upon pressing Save, the address service is not able to find an address that matches what the user entered. But it is able to find a possible match, and returns it as a suggestion. The user is given the option to select the suggested address or force the save with the original address.