我是angualrJs的新手,我创建了一个简单的弹出窗口,其中用户添加了一些任务并提交。有一个按钮作为“添加任务”,动态添加一些字段,用户在这些字段中输入细节。 现在,当用户提交数据时,我的数据没有正确提交,并且未定义。
这是我的html弹出窗口
<div class="modal-header" >
<h3 class="modal-title">Add Sprint</h3>
</div>
<div class="modal-body">
<form name="addSprintForm" data-ng-submit="taskDetail(story)" >
<input type="text" class="form-control" name="sprintNo" data-ng-model="story.sprintno" placeholder="Sprint No">
<div data-ng-repeat = "task in tasks track by $index">
<br/>
<input type="checkbox" data-ng-model="hide">Hide Task
<input type="text" data-ng-hide="hide" class="form-control" name="taskdetail" data-ng-model="story.taskdetail[$index]" placeholder="Task detail"><br/>
<span ng-hide="hide">Total Stories</span>
<select class="form-control" data-ng-hide="hide" name="sprints" data-ng-model="story.sprints[$index]" data-ng-options="sprint for sprint in totalStories" > </select>
{{$index}}
<input type="button" data-ng-hide="hide" data-ng-show="$last" class="remove pull-right" value="-" ng-click="removeTask()"><br/>
</div>
<input type="button" class="btn btn-primary" name="task" ng-click="addTask()" value="Add tasks">
<input type="submit" class="btn btn-primary" value="Save" >
</form>
我的控制器
projectTrackerApp.controller('addSprintPopupCtrl',['$scope',function($scope){
$scope.tasks = [];
$scope.addTask=function(){
var newItemNo = $scope.tasks.length+1;
$scope.tasks.push(newItemNo);
console.log($scope.tasks)
}
$scope.removeTask = function() {
var removeItem = $scope.tasks.length-1;
$scope.tasks.splice(removeItem);
};
var storiesArr = [];
for(var i=0;i<16;i++) {
storiesArr.push(i);
}
$scope.totalStories = storiesArr;
$scope.taskDetail=function(data){
$scope.rohit=data;
alert(data)
}
}])
答案 0 :(得分:0)
您应该尝试直接使用scope
和ng-model
:
$scope.story = {};
$scope.taskDetail = function(){
console.log($scope.story);
}
HTML
<form name="addSprintForm" data-ng-submit="taskDetail()" >