Skip to content

Instantly share code, notes, and snippets.

@chaosmonster
chaosmonster / example.md
Last active November 12, 2016 09:54
Compare Regex syntax angular 1.5 and angular2 template syntax

In Angular1

angular.module('foo', []).directive('btnGroup'['$parse', function($parse) {
    return {
		restrict	: 'E',
		replace		: true,
		scope		: true,
        template	: '',
		link		: function(scope, elem, attrs) {
export interface PizzaContext {
toppings?: string[];
size?: string;
}
export class DefaultPizzaContext implements PizzaContext {
toppings: string[];
size: string;
constructor(form: PizzaContext = null) {
@chaosmonster
chaosmonster / my-chart.component.ts
Created May 24, 2017 07:36
ng2-charts unpassed options
import {Component} from '@angular/core';
@Component({
selector: 'app-my-chart',
template: ` <div>
<canvas baseChart [datasets]="chartData" [labels]="chartLabels" [options]="chartOptions" [legend]="chartLegend"
[chartType]="chartType"></canvas>
</div>`
})
export class MyChartComponent {
public chartOptions: any = {
@chaosmonster
chaosmonster / weird-jasmine-behaviour.md
Created May 24, 2017 16:22
Weird jasmine/ typescript behaviour

I am mocking a ViewContainerRef for a jasmine test. The code to be testes does at one point this: viewRef.element.nativeElement.scrollTop = 5

So I wrote a ViewContainerRefMock

export class ViewContainerRefMock extends ViewContainerRef {

  constructor() {
 super();
/**
*
* Run the following code with `ng test`
* Is this a jasmine, typescript, angular or stupid developer bug?
**/
import {
ComponentFactory,
ComponentRef,
ElementRef,
@chaosmonster
chaosmonster / schema-example.ts
Created June 11, 2017 15:01
CUSTOM_ELEMENTS_SCHEMA and behaviour
@Component({
selector: 'existing-element',
template: `hello World`
})
export class ExistingElementComponent {
}
@Component({
selector: 'root',
template: `
@chaosmonster
chaosmonster / angular-component-composition-with-mixin.ts
Last active January 1, 2019 16:44
Experiment to use mixins to make composition possible for angular components
import {Component} from '@angular/core';
export function sayHi() {
return 'Hi';
}
export function echo(msg) {
return 'Echo:' + msg;
}
@chaosmonster
chaosmonster / router-as-ssot-ngrx.ts
Last active February 21, 2018 18:18
This is a simplified version of how I use the router as SSoT
export class RouteChange implements Action {
readonly type = '[Router] Route Change';
constructor(public payload: { params: any, path: string, queryParams: any }) {}
}
const parseActivatedRouteToUriArray = (routeSnapshot: ActivatedRouteSnapshot): string[] => {
let uri = [];
if (!isUndefinedOrNull(routeSnapshot) && !isUndefinedOrNull(routeSnapshot.routeConfig)) {
const viewPort = document.createElement('meta');
viewPort.setAttribute('name', 'viewport');
viewPort.setAttribute('content', 'width=device-width, initial-scale=1');
document.getElementsByTagName('head')[0].appendChild(viewPort);
export const onInit = <T extends Constructor>(base: T = class {} as T) =>
class OnInitSubject extends base implements OnInit, AfterViewInit {
private _init = new BehaviorSubject<void>(null);
onInit$ = this._init.asObservable();
ngOnInit(): void {
this._init.next();
// tslint:disable-next-line:no-unused-expression
super['ngOnInit'] && super['ngOnInit']();