Javascript angular 9使用querylist(contentChildren或ViewChildren)对dom进行重新排序/排序
我想知道angular是否允许您对兄弟DOM进行重新排序/排序 例如,如果我想重新排列(更改顺序)Javascript angular 9使用querylist(contentChildren或ViewChildren)对dom进行重新排序/排序,javascript,angular,dom,angular9,Javascript,Angular,Dom,Angular9,我想知道angular是否允许您对兄弟DOM进行重新排序/排序 例如,如果我想重新排列(更改顺序)opt组件。我怎么做 my lib select是选择或下拉组件,opt是生成选择选项的子组件 组件是在其他组件中生成或渲染的,如下所示 即app.component.ts {{x} 在mylibselect中,我有一个查询列表 @ContentChildren(OptComponent, {descendants: true, read: OptComponent}) options
opt
组件。我怎么做
my lib select
是选择或下拉组件,opt
是生成选择选项的子组件
组件是在其他组件中生成或渲染的,如下所示
即app.component.ts
{{x}
在mylibselect
中,我有一个查询列表
@ContentChildren(OptComponent, {descendants: true, read: OptComponent})
options: QueryList<OptComponent>;
....
if (this.customComparator) {
const arr = this.options.toArray();
arr.sort(this.customComparator);
this.options.reset(arr);
}
@ContentChildren(OptComponent,{子体:true,读取:OptComponent})
选项:QueryList;
....
if(此.customComparator){
const arr=this.options.toArray();
arr.sort(这个customComparator);
此.options.reset(arr);
}
但这不是对兄弟姐妹排序或排序
我知道,我可以在app.component.ts
中对finalComponents
进行排序,但我想对my lib select
中的选项进行排序
有人能帮我吗
提前谢谢。我觉得你有两种方法来解决这个问题 方法1-在通过ngFor渲染/传递项目之前,对app.component.ts中的项目重新排序
方法2-使用自定义管道重新排序为什么不在“我的库选择分析”中传递FinalComponents并从那里渲染选项。。?在这里对DOM进行排序真的不是一个好的解决方案(它会与角度冲突)是的,我能做到。但是如果我想自定义选项内容。假设我想将图像添加到一些选项中,而另一些不想添加。我知道我可以使用Ng模板,但我仍然想知道是否有可能为了安全起见更改兄弟顺序。