Append element to QueryList Angular

2020-07-11 09:57发布

问题:

Is there a way to append a new element to a QueryList?

For example, i have a QueryList like this:

@ContentChildren(SysColumn) syscolumns: QueryList<SysColumn>;

And i need to append another SysColumn after the view init. Is it poossible on Angular? I try to append but it says that is not a function of a QueryList.

回答1:

You can use reset method

this.syscolumns.reset([...this.syscolumns.toArray(), this.additionalColumn])

Stackblitz Example