我有一个使用 AngularJS 表单验证的 Web 表单,但是当我使用地址查找(使用来自 loqate.com 的 api/脚本)时,输入是通过选择地址来填充的,但是 AngularJS 看不到这些值。表单的响应就像输入为空一样。
表单验证一切正常,但是当输入具有通过地址查找设置的值时,ng-model 什么也看不到,ng-change 没有被触发等等。
我试过调用 $scope.$apply()
但每当调用时我都会收到 $rootScope:inprog
控制台错误。
地址查找调用的脚本似乎是 this, but I can't make head nor tail of it
Here is the form in action .地址在第 2 页,开始输入邮政编码,例如。 'PE' 用于地址选项。
最佳答案
根据 Loqate 文档,您可以使用 event listeners因此您可以通过修改此代码来更新您的模型:
control.listen("populate", function(address, variations) {
// I don't know what fields the received address variable has but
// you just have to check it and apply the necessary changes.
$scope.Contact.address1_postalcode = address.PostalCode;
$scope.Contact.address1_line1 = address.Street;
$scope.Contact.address1_city = address.City;
$scope.Contact.address1_country = address.Country;
});
关于javascript - AngularJS 不检测地址查找输入中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56523428/