Skip to content

Instantly share code, notes, and snippets.

View carmichaelize's full-sized avatar

Scott Carmichael carmichaelize

View GitHub Profile
@carmichaelize
carmichaelize / angularjs-$compile.js
Last active July 18, 2018 09:30
AngularJS $compile example
function MyDirective ($templateRequest, $compile) {
var templateBase = '/directives/my_directive/views/';
var childTemplates = {
child1: 'child1.html',
child2: 'child2.html'
};
return {
@carmichaelize
carmichaelize / capitalize.pipe.ts
Last active August 21, 2016 20:36
Angular2 string capitalisation pipe
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'capitalize'
})
export class Capitalize implements PipeTransform {
transform(str: string, all: boolean) {
//Capitalize all the words
if (all) {
@carmichaelize
carmichaelize / child-1.component.ts
Last active September 7, 2018 08:15
Angular2 component factory resolver example
import { Component } from '@angular/core';
import { ChildBaseComponent } from './child-base.component';
@Component({
template: `This is Child Component 1`
})
export class Child1Component extends ChildBaseComponent {
constructor(){
//Run base constructor
@carmichaelize
carmichaelize / is-online.component.ts
Created February 12, 2017 14:12
Testing for an internet connection.
import { Component } from '@angular/core';
@Component({
template: `
<h1>Is Online: {{ isOnline }}</h1>
<span (click)="clickHandler()">Click Me</span>
`,
})
export class MyComponent {
private baseUrl = 'http://www.test.com';
@carmichaelize
carmichaelize / foo-bar.jsx
Last active July 19, 2017 20:07
Shallow Rendering a Redux Component in React Tests
import React, { Component } from 'react';
import { connect } from 'react-redux';
export class FooBar extends Component {
greet() {
return `Hello ${store.foo} ${store.bar}!`;
}
render() {
@carmichaelize
carmichaelize / foo-component.jsx
Created November 3, 2017 08:55
React — Importing Global Variables from the Window Object
import React, { Component } from 'react';
import Foo from './foo-service';
class FooComponent extends Component {
foo = Foo;
render() {
return (<div>{this.foo.name}</div>)
}
}