我试图将从谷歌地图自动完成 API 中提取的纬度和经度传递给根据这些坐标更新 map 的函数。
如何将变量 {{details1.geometry.location.lat()}} 和 {{details1.geometry.location.lng()}} 的值作为 ng- 中 updateMap() 函数的参数传递模糊=“更新 map ()”
<ion-content padding="true" class="has-header" ng-controller = "pollutionMapCtrl">
<label class="item item-input" id="address-input" name="address">
<i class="icon ion-search placeholder-icon"></i>
<input id = "Autocomplete" type="text" ng-autocomplete ng-model = "result1" details = "details1" options = "options1" ng-blur="updateMap()">
</label>
<div>result: {{result1}}</div>
<div>lat: {{details1.geometry.location.lat()}}</div>
<div>long: {{details1.geometry.location.lng()}}</div>
Controller 文件
.controller('pollutionMapCtrl', function($scope) {
$scope.updateMap = function (lat,lng) {
$scope.map = { center: { latitude: lat, longitude: lng }, zoom: 8 };
}
最佳答案
将参数传递给函数的方式与 Javascript 中普通函数的方式相同:
ng-blur="updateMap(details1.geometry.location.lat(), details1.geometry.location.lng())"
关于javascript - 如何在 Ionic 中仅传递 Controller 变量的值作为参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33859284/