[英]Data binding with provider in Ionic3 and Angular2
In my app, I have a list to display which has a lot of data. 在我的应用程序中,我要显示一个包含大量数据的列表。 The data is getting populated in a provider in a loop from Firebase.
从Firebase循环将数据填充到提供程序中。 Now don't want to wait for the entire data to be loaded.
现在不想等待整个数据被加载。 So how can I bind my page list variable with the provider so that it displays as much as it has fetched?
那么,如何将页面列表变量与提供程序绑定,以使其显示与获取的内容一样多的内容?
Following is the code where I am populating a list in my provider class. 以下是我在提供程序类中填充列表的代码。
dataArray = new Array<any>();
for (let item of items) {
this.afDB.object(`root`+item)
.subscribe(data=> {
this.dataArray.push(data);
});
}
So the dataArray will be populated with time. 因此,dataArray将随时间填充。 Now I a importing the provider class in a page where I want to show the list with the data in dataArray.
现在,我要在页面中导入提供程序类,在该页面中要显示包含dataArray中数据的列表。 If I return dataArray then it has to be after the complete data fetching.
如果我返回dataArray,那么它必须在完整的数据获取之后。 So Is there a way I can bind the dataArray with some variable in my page or use it directly in the page?
那么,有什么方法可以将dataArray与页面中的某些变量绑定或直接在页面中使用它?
Here in the HTML code: 在HTML代码中:
<ion-list>
<ion-item *ngFor="let item of items">
{{item.value}}
</ion-item>
</ion-list>
items is a variable in the page TS file. items是页面TS文件中的变量。
Got my mistake. 弄错了
import { DataProvider } from './../../providers/data/data';
constructor(private _data: DataProvider) {
}
Here I was using Private
for the reference. 在这里,我使用“
Private
”作为参考。 That is why I was unable to use it in the HTML class. 这就是为什么我无法在HTML类中使用它。 It has to be
Public
. 它必须是
Public
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.