Skip to content

Instantly share code, notes, and snippets.

@Bolza
Bolza / gist:b768da0828acfea2100f
Last active August 29, 2015 14:12
Angular Service, Provider, Factory Quick Sintax
// from http://jsfiddle.net/thomporter/zjFp4/1/
var myApp = angular.module('myApp', []);
//service style, probably the simplest one
myApp.service('helloWorldFromService', function() {
this.sayHello = function() {
return "Hello, World!"
};
});
@Bolza
Bolza / tr.js
Created March 9, 2015 18:03
AngularJS Test: Testing Routes
beforeEach(module('app', function($stateProvider) {
$stateProvider.state('default', {
url: '/',
});
}));
@Bolza
Bolza / ng-test-directive-model.js
Last active August 29, 2015 14:16
AngularJS Test: Directive with ngModel
/* jshint -W117, -W030 */
describe('LineItemType', function() {
var scope, compileDirective, spy;
beforeEach(module('app.lineItem', function($provide) {
$provide.service('lineItemType', mockData.lineItemTypeService());
}));
beforeEach(inject(function($injector) {
var $controller = $injector.get('$controller');
@Bolza
Bolza / envConfig.provider.js
Created June 9, 2015 13:14
Attempt to make config loading syncronous in AngularJS
(function() {
'use strict';
var envconfig = angular.module('app.envConfig', []);
envconfig.config(confFunc);
envconfig.provider('startup', startupFactory);
confFunc.$inject = ['startupProvider'];
/* @ngInject */
function confFunc(startupProvider) {
@Bolza
Bolza / myrepeat.js
Created October 15, 2015 10:14
Wraps ng-repeat
app.controller('MainCtrl', function($scope) {
$scope.numbers=[1,2,3,4,5,6];
});
app.directive('myRepeat', function($compile){
return {
//High priority means it will execute first
priority: 5000,
//Terminal prevents compilation of any other directive on first pass
terminal: true,
@Bolza
Bolza / pubSub.js
Last active December 23, 2015 14:45
//`first` reads the data from the service
Controller first (myService) ->
this.firstValue = myService.get().firstValue //using a getter so there's no direct reference
myService.onChange(function(newData) {
this.firstValue = newData.firstValue
})
//`second` sets the data inside the service
@Bolza
Bolza / ng2.hellow.ts
Created February 25, 2016 14:14
NG2 Quick Hello World
/// <reference path="node_modules/angular2/ts/typings/node/node.d.ts"/>
/// <reference path="node_modules/angular2/typings/browser.d.ts"/>
import { bootstrap } from "angular2/platform/browser";
import { Component } from "angular2/core";
@Component({
selector: 'hello-world',
template: <div> Hello World! </div>
})
class HelloWorld {
}
@Bolza
Bolza / ng2_trblshoot.md
Last active October 9, 2016 22:08
NG2 Upgrade Troubleshoot

Reflect-metadata error

  • adding import 'zone.js' and 'reflect-metadata'
  • System.config.babelOptions.stage = 1

RXJS missing / errors

  • update NG2 to >=2.0.0-beta.9, doesnt require external rxjs anymore

Transpiler SyntaxError on any Typescript annotation as Unexpected token

  • npm install --save-dev babel-plugin-transform-decorators-legacy babel-plugin-transform-class-properties babel-plugin-transform-flow-strip-types babel-preset-es2015 babel-plugin-angular2-annotations
  • in gulpfile task add plugins: 'angular2-annotations','transform-decorators-legacy','transform-class-properties','transform-flow-strip-types'
@Bolza
Bolza / wp_ng2_flow.md
Last active July 21, 2016 14:30
Webpack + Angular2 Workflow

Resources

Splitting bundles

Webpack + Angular2 + Typescript Workflow

Setup Project

  1. Install Angular2 deps using npm
  2. Try to directly use import { Stuff } from '@angular/core'
@Bolza
Bolza / anagram-search-exercise.js
Created February 2, 2017 16:09
Anagram Search - Interview Exercise
// Creating the dictionary
var dict = [];
for (var i = 0; i < 100000; i++) {
dict.push('abcdfg');
dict.push('abcdff');
}
var inputWord = 'gfdcba';
// Setup