Javascript DOM就绪后如何执行angularJs函数?
我正在使用GoogleMap&angularJS,我想计算JSON文件中当前位置和另一个位置之间的距离。但距离仅在视图模板中有一个按钮时显示,该按钮通过ng click调用angular JS中的函数:Javascript DOM就绪后如何执行angularJs函数?,javascript,jquery,angularjs,Javascript,Jquery,Angularjs,我正在使用GoogleMap&angularJS,我想计算JSON文件中当前位置和另一个位置之间的距离。但距离仅在视图模板中有一个按钮时显示,该按钮通过ng click调用angular JS中的函数: <button id="show-distance" ng-click="showDistance()">Show Distance</button> 我用以下方式显示距离: <table style="border: 1px solid" class="data
<button id="show-distance" ng-click="showDistance()">Show Distance</button>
我用以下方式显示距离:
<table style="border: 1px solid" class="data-table">
<tr>
<th><?php echo $this->__('Store name')?></th>
<th><?php echo $this->__('Address')?></th>
<th><?php echo $this->__('Distance')?></th>
</tr>
<tr ng-repeat="item in items | filter:query | orderBy:orderProp | limitTo:quantity " ng-controller="ItemController" class="list-locator">
<td ng-click="open(item)">{{item.title}}</span></td>
<td ng-click="open(item)">{{item.address}}</td>
<td ng-click="open(item)">{{item.location}} miles</td>
</tr>
</table>
{{item.title}
{{item.address}
{{item.location}}miles
在不单击任何内容的情况下,如何显示距离 只需在绑定到视图的控制器中调用此块即可
var myApp = angular.module('myApp',[]);
myApp.controller('SomeController', ['$scope', function($scope) {
jQuery.each($scope.items, function (index, value) {
$scope.distance = $scope.getDistance(jQuery.cookie('currentLat'), jQuery.cookie('currentLng'), value['latitude'], value['longitude']);
value['location'] = $scope.distance;
}]);
您可以使用控制器函数来执行代码
function MainControl($scope) {
angular.element(document).ready(function () {
$scope.distance = $scope.getDistance(jQuery.cookie('currentLat'), jQuery.cookie('currentLng'), value['latitude'], value['longitude']);
value['location'] = $scope.distance;
});
}
我只是尝试了一下,但什么都没发生,我想问题是angularJS无法获取当前位置。
function MainControl($scope) {
angular.element(document).ready(function () {
$scope.distance = $scope.getDistance(jQuery.cookie('currentLat'), jQuery.cookie('currentLng'), value['latitude'], value['longitude']);
value['location'] = $scope.distance;
});
}