我在ng-repeat内输入,输入有一个来自数据库的值。我需要将对象的输入发布到服务器但是未定义。但是,当您触摸或更改输入值时,它可以正常工作。为什么输入仅在您触摸或更改值时触发?
HTML
Parse error: syntax error, unexpected 'readphp' (T_STRING), expecting ',' or ';'
JS
<form name="form">
<ul>
<li ng-repeat="val in vals track by $index">
<input type="text" ng-value="val.ID" ng-model="data.val[$index]">
</li>
</ul>
<button type="button" ng-click="Submit()">Submit</button></form>
答案 0 :(得分:0)
<form name="form">
<ul>
<li ng-repeat="val in vals track by $index">
<input type="text" ng-init="data.val[$index] = val.ID" ng-model="data.val[$index]">
</li>
</ul>
<button type="button" ng-click="Submit()">Submit</button></form>
答案 1 :(得分:0)
var app = angular.module('app', []);
app.controller('Controller', function($scope){
$scope.data = {val:{}};
$scope.Submit = function(){
var formdata = JSON.stringify($scope.data.val);
$http.post("post.php", {"val":formdata})
.then(function(response){
console.log(response.data);
});
}});