javascript - 如何在 Ionic 中仅传递 Controller 变量的值作为参数

标签 javascript angularjs ionic-framework

我试图将从谷歌地图自动完成 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/

相关文章:

javascript - AngularJS 从服务内部调用服务 - 服务未定义

javascript - 在 $http 拦截器中重新调用 $http 请求

javascript - 如何使用 Angularjs 重新加载页面?

javascript - 如何解决TrackingPage.html :24 ERROR TypeError: Cannot read property 'unsubscribe' of undefined?

javascript - 使用 ionic 触摸事件更新 moment.js 持续时间

javascript - 使用 Transform 的 Z 索引堆叠问题

javascript - jQuery或javascript查找页面的内存使用情况

ionic-framework - ionic 包无法安装

javascript - 如何让提示框输入调用函数?

javascript - 用于时间跟踪的正则表达式验证