Typescript: Wait for all promises
<p>i got a small problem with my promises. </p>

<p>This is my function:</p>

<pre><code>public generateMealPlanForAWeek(myMealProfile: any, totalCalories:number):Promise&lt;any&gt; {
        return new Promise(resolve =&gt; {
            let mealplan:Array&lt;any&gt; = [];
            for (let i = 1; i &lt;= 7; i++) {
                this.generateMealPlanForOneDay(myMealProfile, totalCalories).then(data =&gt; {
                    mealplan.push(data); // resolves much later
                });
            }
            resolve(mealplan); // is resolved instant
        })
    }
</code></pre>

<p>My problem is, that "generateMealPlanForOneDay" is resolved later then the mealplan itself. </p>

<p>Mealplan is an array of objects (meals in this case).</p>

<p>When i want to save my mealplan, the mealplan is empty:</p>

<pre><code>this.storage.set('Mealplan', JSON.stringify(mealplan)).then(....) // meal plan is Array[0]
</code></pre>

<p>Whats the best way to resolve all meals of my meal plan and then save it?</p>