Cascading Observables

Mike BerrymanIn my Observables in Parallel blog post I discussed how I’ve been moving away from Promises in favor of Observables and how to translate functionality from promise-based solutions to observable-based solutions.  The aforementioned blog post discussed how to wait for multiple Observables to complete before performing some action.  In that scenario all the Observables were independent of each other, meaning none of the Observables depended on the results of another.

In this blog post I’m going to discuss how to use Observables that do depend on a different Observable to complete before executing – AKA Cascading Observables.  One such use case scenario for Cascading Observables is when you need to call a web service to get some data, then use that data to call another web service, all in a single operation.

Continue reading “Cascading Observables”

Observables in Parallel

Mike BerrymanSince observables are being heavily pushed in Angular 2 I’ve been spending some time getting acquainted with how to use them.  Specifically I’ve been “translating” from a promise-based solution to an observable-based solution for certain functionality I’ve been using promises for.  In this blog post I’m going to address how to utilize observables in parallel.

When I say “observables in parallel”, what I mean is multiple observables that are called all at once with the calling code waiting for all the observables to complete their respective actions before continuing.  With promises you could create an array of promises, then utilize the Promise.all() function to wait until all the promises have completed before moving on.  Each individual promise would utilize the .then() function to do whatever needs to be done with that promises’s results.

Continue reading “Observables in Parallel”

Angular 2 TemplateRef Usage

Mike BerrymanAngular 2 is the hot new thing, but like any other new technology out there, documentation and examples are really sparse and there’s a lot of head scratching trying to figure out why things that seem like they should work…aren’t.

I spent some time recently working with TemplateRefs in Angular 2, trying to access templates defined via a <template> tag in my HTML from the component code.

Continue reading “Angular 2 TemplateRef Usage”

Using External Modules in TypeScript

Joseph DotsonWhen programming in TypeScript, you may need to use existing JavaScript modules. This should be a lot easier than it is. You should be able to just use a require and pass a flag in to let the compiler know that it’s a js library in order to convert it to an Any, however that is not possible.

What actually needs to be done is the creation of a .d.ts file. This file (or files) declares the shape of the module. This includes any functions or interfaces that might be needed used when using the class.

Continue reading “Using External Modules in TypeScript”