我在這裏有一個簡單的代碼,並希望將數據傳遞給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