Skip to content

Instantly share code, notes, and snippets.

View jmahmood's full-sized avatar

Jawaad Mahmood jmahmood

View GitHub Profile
@jmahmood
jmahmood / service.ts
Last active May 3, 2022 21:34
Using JavaScript Generators with Angular2+
// I use generators a lot with python. It seems elegant to me; keep only the data you need and iterate along.
// I was happy to see that they had added generators to JavaScript and had an example where I needed the next 30 days.
// I could put it in an array, but why not try using generators?
// After trial and error, I realized it isn't quite possible in Angular
// Attempt #1: Use Generator function directly in ngFor.
static *next30DaysPlainGenerator = function*(){
const initial_date = new Date();