我正在製作一個離子/角度的網絡應用程序,用戶可以從Google地圖彈出的模式或從Google地圖自動完成搜索框。
爲了獲得最佳用戶體驗,我希望用戶在地圖上選擇的地址輸入到搜索框中。
如果我先在地圖上選擇一個位置,然後通過輸入工作的搜索框來改變位置。但是,如果我先在搜索框中鍵入位置,然後嘗試在地圖上選擇一個位置,則輸入框中的文本保持不變。
我認爲這是你需要獲得自動完成工作
$scope.disableTap = function(){
container = document.getElementsByClassName('pac-container');
// disable ionic data tab
angular.element(container).attr('data-tap-disabled', 'true');
// leave input field if google-address-entry is selected
angular.element(container).on("click", function(){
document.getElementById('searchBar').blur();
});
};
這裏的離子指令做的是搜索框聲明
var input = document.getElementById('searchBar');
var autocomplete = new google.maps.places.Autocomplete(input);
我有一個搜索框關聯的NG-模型
<input type="text" id="searchBar" ng-focus="disableTap()" placeholder="Type address here..."
ng-model="inputText">
我正在更新autocomp中的$ scope.inputText變量勒特監聽器,如下:
$scope.inputText = autocomplete.getPlace().formatted_address;
,並在地圖上監聽器,如下:
$scope.inputText = address.formatted_address;
是否殘影功能覆蓋NG-模式?我弄錯了嗎?
任何人都可以看到爲什麼我的ng模型更新,如果我有地圖然後搜索框,但不是搜索框然後地圖?
任何幫助,將不勝感激感謝
你可以在plunker或jsfiddle上發佈樣本嗎? – Hoyen