Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html ngModel的副本也会受到影响_Html_Angular_Angular Directive - Fatal编程技术网

Html ngModel的副本也会受到影响

Html ngModel的副本也会受到影响,html,angular,angular-directive,Html,Angular,Angular Directive,我正试图通过此函数存储所有学生详细信息。 考虑每个学生都有名称和数组[]/Cord>命名数字标记(为简单起见) 考虑从1到10的总选项 因此,我使用了一个多选下拉列表(自定义组件),并像这样输入ngModel, 在TS中,我用制作了一种字典数组。 options=[{id:1,text:"one",..... till 10] 我得到 (2) [2,1] [2] 温总理说, 0:2 1:333 真的 2->不是数组,而是数字 所以下一次选择时,它会说push不是一个函数,因为它被转换成了一个

我正试图通过此函数存储所有学生详细信息。 考虑每个学生都有<代码>名称<代码>和<代码>数组[]/Cord>命名数字标记(为简单起见)

考虑从1到10的总选项 因此,我使用了一个
多选下拉列表
(自定义组件),并像这样输入
ngModel
, 在TS中,我用

制作了一种字典数组。
 options=[{id:1,text:"one",..... till 10]
我得到 (2) [2,1]

[2] 温总理说, 0:2 1:333

真的 2->不是数组,而是数字

所以下一次选择时,它会说push不是一个函数,因为它被转换成了一个数字?为什么推后的数组实例变成了一个数字?

请这样尝试:

this.studentsCopy = [...this.students]
或者


扩展运算符(
)可用于初始化来自另一个数组或对象的数组和对象,无需引用(深度复制)

这是您的引用问题,您可以使用lodash解决此问题

this.studentsCopy = _.cloneDeep(this.paginatedResponse['result']);

试试修改后的答案谢谢,它成功了!将在批准的最短时间到期后批准答案!我们如何将一个元素推送到复制的元素console.log(this.student[index].marks)console.log(this.studentCopy[index].marks)this.studentCopy[index].roles=this.routeCopy[index].marks.push(333)console.log(this.studentCopy[index].marks)它说推不是一个函数,日志返回的结果类似于[1,2,3]然后错误显示
console.log(this.studentCopy[index].marks)的输出
为此,
console.log(this.routes[index].roles)console.log(this.routeCopy[index].roles)console.log(this.routeCopy[index].roles)this.routeCopy[index].roles=this.routeCopy[index].roles.push(222)console.log(this.routeCopy[索引].roles)
我得到了(2)[2,1][2]wen打开的是0:2 1:333 true 2->不是一个数组,而是一个数字,所以在select上的下一个类型表示push不是一个函数,因为它被转换成了一个数字。在回答一个问题后,如果你遇到另一个问题,你应该问一个新问题,而不是编辑现有的问题。但是,stackbil有一个问题tz我无法在自定义multiselect(cookedup名称)中导入,因为它是我工作的公司的内部UI组件,即不应共享
    console.log(this.routeCopy[index].roles)
    console.log(this.routeCopy[index].roles instanceof Array)
    this.routeCopy[index].roles = this.routeCopy[index].roles.push(333)
    console.log(this.routeCopy[index].roles)
this.studentsCopy = [...this.students]
this.studentsCopy = this.students.map(object => ({ ...object }))
this.studentsCopy = _.cloneDeep(this.paginatedResponse['result']);