我的控制器:AngularJS - 如何從GET方法獲取數據
angular.module('apartmentCtrl', [])
.controller('ApartmentController', function ($scope, $http, Apartment) {
$scope.loading = true;
$scope.myLocation = '';
Apartment.get($scope.myLocation).success(function (data) {
$scope.apartments = data;
$scope.loading = false;
});
});
我的服務 angular.module( 'apartmentService',[])
.factory('Apartment', function ($http) {
return {
get: function (myLocation) {
//return $http.get('/api/apartments');
return $http({
method: 'GET',
url: '/api/apartments',
//headers: {'Content-Type': 'application/x-www-form-urlencoded'},
params: {location: myLocation}
});
}
};
});
我的HTML:
<input type="text" name="myLocation" class="form-control" ng-model="myLocation">
如何從AngularJS的GET方法獲取數據並將其傳遞給params
請出示你的代碼。你使用Angular提交表單嗎? – 2015-02-10 02:20:08
你可以使用'$ http'來做到這一點。 http://www.w3schools.com/angular/angular_http.asp – 2015-02-10 02:32:05
你必須在控制器中使用'$ http'服務。請顯示您的代碼 – nosthertus 2015-02-10 02:32:58