【发布时间】:2019-11-17 04:28:14
【问题描述】:
我有一些带有ng-model="award.questions.propertyName" 的文本区域。我需要将这些输入值放入具有这种结构的数组中:
questions: [{
key: value,
key: value,
...
}]
但是console.log 在我提交表单时将此值返回为未定义。
当我将问题定义为对象{} 时,它的作用就像一个魅力并且所有值都很好,但是当我将它放入数组时,它就没有任何作用。
查看
<textarea name="short-Description" ng-model="award.questions.shortDescription"></textarea>
<textarea name="consumer" ng-model="award.questions.consumer"></textarea>
<textarea name="advantages" ng-model="award.questions.advantages"></textarea>
控制器
$scope.award = {
questions: [{
shortDescription: $scope.shortDescription,
consumer: $scope.consumer,
advantages: $scope.advantages,
}],
};
$scope.onSubmit = (award, awardForm) => {
$scope.data = angular.copy(award);
console.log($scope.data);
}
【问题讨论】:
-
我不确定我是否完全理解这种情况。
textareas 在ng-repeat里面?你能显示你提到的form吗(onSubmit)。
标签: javascript arrays angularjs object