我有以下表格
<div ng-controller="Formctrl">
<form ng-submit="getNames(pd)">
<fieldset>
<div class="row">
<section class="col col-4" ng-repeat="n in [] | range:5">
<label class="input">
<input type="text" placeholder="Names" ng-model="pd.names[$index]" >
</label>
</section>
</div>
</fieldset>
</form>
</div>
基本上我想在数组表单提交中绑定名称。但我收到以下错误
TypeError: Cannot set property '0' of undefined
这是我的控制器
angular.module('myApp')
.controller('FormCtrl', function($rootScope,$scope){
$scope.pd = {};
$scope.getNames = function() { console.log($scope.pd); };
});
我需要输出如下所示。我如何实现它??
{
names: [
'Name 1',
'Name 2',
'Name 3',
'Name 4',
]
}