我目前處於初學者級別的javascript和angular.js框架。 我的問題是我無法使ngResource
工作。請求REST服務
我的代碼:
JS:
var geolocationControllers = angular.module('geolocationControllers', ['ngResource']);
geolocationControllers.controller('geolocationControllers', ['$scope', '$resource',
function($scope, $resource) {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
$scope.$apply(function() {
$scope.position = $resource('http://nominatim.openstreetmap.org/reverse?format=json', {}, {
query: {
method: 'GET',
params: {
lat: position.coords.latitude,
lon: position.coords.longitude
}
}
});
console.log($scope.position);
});
});
}
}
]);
HTML:
<div class="container" ng-controller="geolocationControllers">
<label for="location">Your location:</label>
<input type="text" id="location" size="120" ng-model="position"/>
</div>
此輸出到控制檯,並且也是輸入元件:
function Resource(value) { shallowClearAndCopy(value || {}, this); }
你介意提供的是什麼,你現在有一個[plunker(http://plnkr.co/)? – Dom 2014-12-07 19:12:10
我終於找到了一些時間,並添加了砰砰聲:) – Joe 2014-12-13 22:56:38