Posts

Showing posts from 2017

Create PDF's in Angular / Typescript

Posting an example of how to create PDFs directly in the browser with no server involved using Angular, Typescript and pdfmake.org.

The demo is here: https://fintechneo.github.io/angular2-templates/

The PDF creation is initiated in the createPDF() method of this source: https://github.com/fintechneo/angular2-templates/blob/master/app/pages/accountreportcomponents.ts

The pdfmake library is made available to Angular and Typescript by creating a script element inside an rxjs/Observable that is notified on the script element onload. You can see how it's done in here: https://github.com/fintechneo/angular2-templates/blob/master/app/pdfmake/pdf.service.ts

Simple Firebase service for Angular 2

If you want a very simple alternative to Angularfire you may create a firebase service very easily. I made this to avoid extra configuration when it comes to adding npm packages and configuring for bundling. This is done by downloading the scripts from Firebase CDN directly by using a dynamically created script tag.

Once the service is initialized you'll find the database in the public database property, and you just use the regular Firebase API. (Example: this.fbservice.database.ref('someproperty').set(somevalue) - and remember to have fbservice : FireBaseService in your component constructor to inject the service. )

And here's the code for the service:
import{Injectable}from'@angular/core';import{Observable}from'rxjs/Observable';declareconstfirebase : any;constconfig={apiKey:"",authDomain:".firebaseapp.com",databaseURL:"",storageBucket:".appspot.com",messagingSenderId:"",};@Injectable() exportclassFireB…