簡體   English   中英

在Angular 4中需要從服務到組件獲取大量數據

[英]Need to get large chunk of data from service to component in Angular 4

我需要通過服務將非常大的對象傳遞給組件。 由於對象非常大,因此我打算將對象分成多個塊。 我如何間隔發送服務'getData()'請求以逐塊獲取數據? 基本上我不希望數據一次來自服務,而是成塊地發送。 例如,如果數據是這樣的-{'x':'1','y':2,'z':3},則數據首先出現x,然后是y,依此類推。 在此先感謝您的注意。

選項1:收到數據后,將其轉儲到本地存儲或Cookie中,然后在需要時讀取。

選項2:如果您有這么大的數據,請對帶角度的indexDB進行一些RND。 它會幫助你。 :) –

npm我indexddb-angular

在這種情況下,RxJs 分區運算符可能會有所幫助。 假設“大對象”是帶有鍵的嵌套對象,則可以實現一些邏輯以按所需順序返回。

const obj = {fist: {name: 'joe', age: 30}, second: {name: 'doe', age: 40}};
//Turn it into iterable
const array = Object.entries(obj);
// make an observable
const source = from(array);
// Logic for how to split, depends on your obj structure
const [under, over] = source.pipe(partition(val => val[1].age < 40));
// result
under.subscribe(a => console.log("Under 30: " + a));
over.subscribe(a => console.log("Over 30: " + a));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM