I'm building a custom multi drag-and-drop functionality into an angular app, and in one of the services, I iterate through an array of host components (<app-cell>
).
当我遍历s的数组时,有没有办法为我的迭代变量分配“自定义类型”?换句话说,如何将tile的类型限制为app-tile?
这不是确切的代码,但是或多或少地说明了我正在尝试实现的目标。
let selectedTiles = Array.from(document.querySelectorAll('app-tile'));
selectedTiles.map((tile: **WHAT GOES HERE?**) => {
// do something with tile
}
之前,我曾使用模型对具有特定键的简单对象进行“自定义键入”,但我不知道如何尝试缩小对自己的角度分量的分配。
从我自己的谷歌搜索来看,TemplateRef或指令似乎在正确的道路上,但是我对两者的理解都很模糊,可以针对我可以使用的类型使用一些指导!谢谢!
It really depends on what type “selectedTiles” is. Its type will be something like
Array<T>
, suppose here it is some type{ id: number, dataset: Array<string> }
. Since you are mapping over the selectedTile array, each element (here "tile") will of typeT
.具体来说,请您分享使用的服务。另外,如果可以,您可以共享代码链接