0
HTML表單代碼想要得到的表單元素的值在AngularJS陣列
<form ng-submit="mysubmit()" ng-controller="question_post" >
<textarea name="question" id="question" ng-model="question"></texarea>
<input type="text" name="opt[]" ng-model="opt[]" />
<input type="text" name="opt[]" ng-model="opt[]" />
</form>
角JS代碼
var obj = angular.module('root', []);
obj.controller('question_post', ['$scope','$http', function ($scope,$http) {
$scope.mysubmit = function(){
$http({
url: "some_url",
method: "POST",
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
data:$.param({user_id:1,'question':$scope.question,'option':$scope.opt})
}).success(function(data, status, headers, config) {
console.log(data);
alert(data);
$scope.data = data;
}).error(function(data, status, headers, config) {
$scope.status = status;
});
}
}]);
上面將返回錯誤代碼的時候我寫ng-model="opt[]"
和ng-model="opt"
返回一個值。
我想添加名稱爲opt
的動態文本字段,爲此我想獲取數組中的opt
值。 如果我使用PHP然後它好吧($option =$_POST['opt'])
但我怎麼能得到在AngularJS中的數組值opt
。