【发布时间】:2018-03-29 21:38:00
【问题描述】:
我有一个 ListView 的自定义组件,它接收一个布尔值 @Input() 属性,该属性负责显示模板的某些部分。
这是ListView:
<ListView [items]="photos">
<ng-template let-item="item">
<app-post [photo]="item" [displayInfo]="display"></app-post>
</ng-template>
</ListView>
display 变量设置为false。
这是app-post 模板:
<StackLayout *ngIf="displayInfo" verticalAlignment="center">
....
</StackLayout>
其中displayInfo 是输入属性。
在app-post 组件中,我有将displayInfo 值更改为true 的逻辑。
然而,我注意到ListView 只创建了几个组件,而不是在向下滚动时重用它们。
这会导致以下(示例)场景:
- 5 个
app-post组件列表,全部以displayInfo为假 - 点击第一个
app-post组件集displayInfo为真 - 3d 和 5th
app-post组件已将displayInfo设置为 是的
如何避免这种行为并将所有自定义组件的属性设置为列表视图中指定的值?
【问题讨论】:
标签: nativescript angular2-nativescript