我正在寻找将非绑定(正确的术语?)表单数据传递给控制器方法的最佳方法。我将如何访问表单的对象及其值?
HTML
<html ng-app="app">
<body ng-controller="MainController as main">
<ng-form name="add_lead_form">
<div ng-repeat="label in form.lead_labels track by $index" ng-show="label.visible">
<div class="input-group lead-data">
<span class="input-group-addon">{{getLabel(label)}}</span>
<input ng-model="add_lead_form.addleadValue[$index]" name="addleadValue" type="text" class="form-control" aria-describedby="basic-addon1">
<input type="hidden" ng-model="add_lead_form.addleadLabelId[$index]" name="add_lead_form.addleadLabelId" ng-value="label.id" />
</div>
</div>
<div class="pull-right"><button ng-click="addLead()" class="btn btn-primary btn-lg">Save Lead</button></div>
</ng-form>
</body>
</html>
app.js
var app = angular.module('app', []);
app.controller('MainController', ['$scope', function($scope) {
$scope.addLead = function() {
console.log($scope.add_lead_form);
};
}]);
答案 0 :(得分:1)
You could not access form inside ng-repeat
,要创建正确的表单,您可以在innerForm
中添加新的ng-repeat
,您必须通过添加新的{{}来更改您的html结构1}}
innerForm
使用上面的代码试试,谢谢