【发布时间】:2015-12-24 02:42:57
【问题描述】:
我在这里有一个简单的代码,想将数据传递给 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 或通过提交表单操作将其发送到控制器
-
因为我想学习 Angular @patricio