【问题标题】:How to post a json to my app ionic => symfony fosrestbundle如何将 json 发布到我的应用程序 ionic => symfony fosrestbundle
【发布时间】:2016-05-21 12:47:21
【问题描述】:
【问题讨论】:
标签:
angularjs
ionic-framework
fosrestbundle
ngresource
【解决方案1】:
你做得怎么样?
首先你需要像这样将函数绑定到你的html:
<button class="button button-energized" ng-click="login()">Login</button>
建议使用服务进行http调用,但需要在控制器中注入(LoginService):
.controller('LoginCtrl', function($scope, LoginService) {
$scope.login = function() {
LoginService.loginUser($scope.data.user, $scope.data.password)
.then(function (data) {
//grant access to the app
});
};
});
为您服务:
.factory('LoginService', function($http) {
return {
loginUser: function(user, password) {
return $http.post('http://mydomain/login', {
user: user,
password: password
});
}
};