我试图在我的 $resource Venue 对象中使用 $scope.lat 和 $scope.lng,这样 REST 通信将始终在某个位置的上下文中。在 HenriettaCtrl 中定义它们之前,我无法判断它们是否在 $rootScope 下被传递,或者它们是否甚至被传递:
henriettaApp = angular.module('henriettaApp', ["ngResource"])
henriettaApp.factory "Venue", ["$resource", "$rootScope", ($resource, $rootScope) ->
console.log($rootScope.lat)
console.log($rootScope.lng)
$resource("/venuesNear/:id",{lat:$rootScope.lat,lng:$rootScope.lng,id:"@id"}, {update: {method:"PUT"}})
]
@HenriettaCtrl = ["$scope", "Venue", ($scope, Venue) ->
saveLocation = (position) ->
$scope.lat = position.coords.latitude
$scope.lng = position.coords.longitude
console.log($scope.lat)
$scope.streams = Venue.query()
navigator.geolocation.getCurrentPosition saveLocation
]