我想推送$scope.planlist=[]中的空白记录,但显示出相同的行为

I want to push blank record in $scope.planlist=[] but shows identical behaviour

本文关键字:记录 空白 显示 scope planlist      更新时间:2023-09-26

我想推送$scope.planlist=[]中的每个空白记录,并在html中迭代以显示其模板,但当我填充记录时,每个记录都显示出相同的行为,这意味着每个属性无法与索引绑定。这可能意味着属性无法唯一定义

$scope.listOfPlans=[];
$scope.planrecord={name:"",age:""};

像这样推动

 $scope.listOfPlans.push(planrecord);

我想填充模板中的每个记录,以便每个属性都可以保存在数组的各自索引中的唯一列表或对象中

您应该在该函数体中创建新对象。有关更多信息,请参阅Angular Formly:在用户单击时动态添加表单字段

另请参阅以下答案JavaScript中变量的范围是什么?

像这样。

 $scope.add = function(){
   var newObject = {name:"",age:""};
   $scope.listOfPlans.push(newObject);
 }