Angular 如何获取角拖放组件中的数组长度
我想在下拉列表中显示访问过的国家(您去过哪里) 如何在我的Ionic应用程序中解决此问题Angular 如何获取角拖放组件中的数组长度,angular,ionic-framework,drag-and-drop,angulardraganddroplists,Angular,Ionic Framework,Drag And Drop,Angulardraganddroplists,我想在下拉列表中显示访问过的国家(您去过哪里) 如何在我的Ionic应用程序中解决此问题 你去哪里了 {{item.name} 完成=[ {url:'https://www.countryflags.io/ad/shiny/64.png,名称:'安道尔'}, {url:'https://www.countryflags.io/ae/shiny/64.png,名称:'阿联酋'}, {url:'https://www.countryflags.io/at/shiny/64.png,名字:'奥地
你去哪里了
{{item.name}
完成=[
{url:'https://www.countryflags.io/ad/shiny/64.png,名称:'安道尔'},
{url:'https://www.countryflags.io/ae/shiny/64.png,名称:'阿联酋'},
{url:'https://www.countryflags.io/at/shiny/64.png,名字:'奥地利'},
{url:'https://www.countryflags.io/au/shiny/64.png,名称:'澳大利亚'},
{url:'https://www.countryflags.io/aw/shiny/64.png,名称:'阿鲁巴'},
{url:'https://www.countryflags.io/bg/shiny/64.png,名称:'保加利亚'},
{url:'https://www.countryflags.io/ch/shiny/64.png,名称:'瑞士'},
{url:'https://www.countryflags.io/cn/shiny/64.png名称:"中国",,
];
drop(事件:CdkDragDrop){
if(event.previousContainer==event.container){
moveItemInArray(event.container.data、event.previousIndex、event.currentIndex);
}否则{
transferArrayItem(event.previousContainer.data,
event.container.data,
event.previousIndex,
事件(当前索引);
}
}
}
我想在下拉列表中显示访问过的国家(您去过哪里)
如何在我的Ionic应用程序中解决此问题
https://mytopcountries.web.app/tabs/home
您可以使用以下语法将索引值设置为HTML元素的属性:
YOUR HTML ELEMENT:
<div class="example-box" *ngFor="let item of done"; let i = index" [attr.data-index]="i" cdkDrag>
... </div>
您的HTML元素:
所有数组都在迭代,基本上我只想显示“访问的55个国家”
{{done.length}}访问过的国家
谢谢,到目前为止一切正常,但所有数组都再次显示。基本上我希望显示的“55个访问过的国家”已经应用:{{done.length}}访问过的国家所以你只需使用“let done=count”,并且{{done}}将是你的总数:)
<div class="example-box" *ngFor="let item of done; index as i" crkDrag>
//And use it like that
<p> {{i+1}} {{item}} </p>
</div>
<div class="example-box" *ngFor="let item of done; " [attr.data-index]="i" cdkDrag>
<p> {{done.length}} countries visited</p>
</div>