我的控制器: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