Skip to content

Instantly share code, notes, and snippets.

Reading data before application startup in Angular 2

In this demonstration I will show you how to read data in Angular2 final release before application startup. You can use it to read configuration files like you do in other languages like Java, Python, Ruby, Php.

This is how the demonstration will load data:

a) It will read an env file named 'env.json'. This file indicates what is the current working environment. Options are: 'production' and 'development';

b) It will read a config JSON file based on what is found in env file. If env is "production", the file is 'config.production.json'. If env is "development", the file is 'config.development.json'.

@joshorvis
joshorvis / rxjs subjects.md
Created February 11, 2018 04:14 — forked from orod/rxjs subjects.md
Subject, ReplaySubject, BehaviorSubject in RxJS

1 source, Three subscribers
Subscriber 1 subscribes and source starts emitting
Subscriber 2 subscribes halfway
Subscriber 3 subscribes after source has completed.

import Rx from 'rxjs/Rx';

var data = [];
@joshorvis
joshorvis / sampleBoxFileUpload.js
Created March 25, 2016 14:21 — forked from seanrose/sampleBoxFileUpload.js
A sample file upload in javascript to the Box API
// Requires JQuery and CORS enabled for the Origin you're testing from.
// Uncomment the next 4 lines to import JQuery
// var script= document.createElement('script');
// script.type= 'text/javascript';
// script.src= '//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.0/jquery.min.js';
// document.head.appendChild(script);
// Set up the multipart form using HTML5 FormData object
// https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest/FormData
var form = new FormData();
@joshorvis
joshorvis / I Dream in Code.js
Created October 24, 2015 19:45 — forked from katowulf/I Dream in Code.js
I Dream in Code...
/*********************
** I Dream in Code **
*********************/
while( I .sleep() ) {
I.dream() in code;
I.dream() in algorithms;
I.dream() in subroutines;
Rewind.age(5) && I.dream.of(["missing pants", "driving hotwheels", "peeing in fountains"]) ); //hint: it’s my bed
@joshorvis
joshorvis / inc_id_rules.js
Last active August 29, 2015 14:27 — forked from katowulf/inc_id_rules.js
Security rules for creating an incremental, numeric ID in Firebase
{
"rules": {
".read": true,
".write": false,
"incid": {
"counter": {
// this counter is set using a transaction and can only be incremented by 1
// the total number of records must be less than 10,000 simply for demo purposes
".write": "newData.isNumber() && ((!data.exists() && newData.val() === 1) || newData.val() === data.val()+1) && newData.val() <= 10000"
},
/**
*
* @author Gabriel Alonso <gbr.alonso@gmail.com>
*
* Angular Modal Service
*
* Requiere Bootstrap's modal (http://getbootstrap.com/javascript/#modals)
*
* Example:
*
<html>
<head>
<!-- Vidyard player API script -->
<script src="//play.vidyard.com/v0/api.js"></script>
<!-- Google Analytics tracking code -->
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXXX-X']);
_gaq.push(['_trackPageview']);
<html>
<head></head>
<body>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type='text/javascript'>
window.onload=function() {
$("#video_container").html('<script type="text/javascript" id="vidyard_embed_code_oTDMPlUv--51Th455G5u7Q" src="//play.vidyard.com/oTDMPlUv--51Th455G5u7Q.js?v=3.1&type=inline"><\/script>');
};
</script>
<div id='video_container'>
<htmL>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script type="text/javascript">
function getEmbedCode(uuid) {
var script=document.createElement('script');
script.type='text/javascript';
script.id='vidyard_embed_code_'+uuid;
script.src='https://play.vidyard.com/'+uuid+'.js?v=3.1&type=inline';
return script;
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script type="text/javascript">
function getEmbedCode(uuid) {
var script=document.createElement('script');
script.type='text/javascript';
script.id='vidyard_embed_code_'+uuid;
script.src='https://play.vidyard.com/'+uuid+'.js?v=3.1&type=inline';
return script;