我在这里有一个简单的代码,并希望将数据传递给laravel控制器,以便将其存储到数据库。我的代码是:将窗体数据传递给使用AngularJS的laravel控制器
AccountController.php
public function store(Request $request)
{
Account::create(array(
'email' => $request->get('email'),
'name' => $request->get('text'),
'age' => $request->get('age'),
));
return ['success' => true];
}
刀片
<form ng-submit="newAccount()">
<div class="form-group">
<label for="email">Email address</label>
<input type="email" class="form-control" id="email" ng-model="accountData.email">
</div>
<div class="form-group">
<label for="fullname">Full Name</label>
<input type="email" class="form-control" id="fullname" ng-model="accountData.name">
</div>
<div class="form-group">
<label for="age">age</label>
<input type="email" class="form-control" id="age" ng-model="accountData.age">
</div>
</form>
app.js
var app = angular.module('accountsApp', []);
app.controller('accountsCtrl', function($scope, $http) {
$scope.newAccount = function() {
//add data
$http.post('/api/accounts',
{
//what will I put here to get the textbox values?
}).
.success(function(response) {
scope.accounts = response;
})
.error(function(response) {
console.log(response);
});
};
});
由于你可以在我的app.js
中看到,我被困在如何从我的刀片中的文本框中获取数据。是否有捷径可寻?谢谢。
为什么不使用jquery这么简单的事情?你想通过Ajax或通过提交表单动作 – patricio
发送给控制器,因为我想学习Angular @patricio – FewFlyBy