Skip to content

Instantly share code, notes, and snippets.

View petebacondarwin's full-sized avatar

Pete Bacon Darwin petebacondarwin

View GitHub Profile

@cheatsheetSection Class decorators @cheatsheetIndex 4 @description {@target ts js}import {Directive, ...} from 'angular2/angular2';{@endtarget} {@target dart}import 'package:angular2/angular2.dart';{@endtarget}

@cheatsheetItem syntax(ts js): `@Component({...})

@petebacondarwin
petebacondarwin / index.html
Created November 25, 2015 10:21
AngularJS issue 13374
<!DOCTYPE html>
<html>
<head>
<script src="https://code.angularjs.org/1.4.8/angular.js"></script>
<script type="text/javascript">
angular.module('app', [])
.run(function($http, $log) {
var _url = 'test.pdf';
@petebacondarwin
petebacondarwin / index.html
Last active October 12, 2015 10:46
ngUpgrade vanilla Angular 1 example
<!doctype html>
<html>
<title>Angular Upgrade 1.0</title>
<style>
user {
background-color: lightyellow;
border: 2px solid darkorange;
display: inline-block;
width: 150px;
padding: 1em;
@petebacondarwin
petebacondarwin / app.js
Created October 11, 2012 14:01 — forked from ggoodman/app.js
AngularJS@1.0.2 + Jasmine
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.name = 'World';
});
@petebacondarwin
petebacondarwin / index.html
Created March 27, 2012 12:23
AngularJS 1.0 - Masked Input Widget
<input ng-model="contact.phone" ui-mask='"(9999) 9999 9999"' placeholder="(01234)-5678-8901" required />
angular.module('myApp', []).service('Partners', function($resource) {
return $resource({ ull:myUrl},function(Partners, rsrcMethod){
Partners.externalize = function(self) {
var myself = angular.copy(self);
return {data: myself};
};
Partners.query = rsrcMethod('', {response: 'response.data.response.data'});
@petebacondarwin
petebacondarwin / app.coffee
Created March 13, 2012 21:09
Handlers in Angular Routes
angular.module('AppConfig',[])
.config(['$routeProvider', ($routeProvider)->
updateQuestionnaire = (scope, next)->
questionnaire = next.params.questionnaire ? ''
scope.$root.questionnaireId = questionnaire
updateQuestionnIndex = (scope, next)->
questionIndex = Number(next.params.questionIndex)
if questionIndex? and not isNaN(questionIndex)
scope.$root.questionIndex = questionIndex
###
Currently if you want to use a coffee script class for an AngularJS service
the syntax for the dependency injection is a bit clunky: you have to define
the dependencies in multiple places
###
class SomeServiceClass
constructor: (@$dep1, @$dep2)->
# Initialize the service
someMethod: ()=>
var oldModelValue, newModelValue, counter;
function watchModelFn(scope) {
newModelValue = ngModelGet(scope);
if (
!updatingFromTheView &&
!(newModelValue === undefined && $valid === false) &&
!modelEquals(newModelValue, oldModelValue)
) {
@petebacondarwin
petebacondarwin / survey.coffee
Created January 9, 2012 21:31
Spine Nested Models
Spine = require('spine')
require('spine/lib/relation')
class Survey extends Spine.Model
@configure 'Survey', 'name', 'title', 'description'
@hasMany 'questions', Question
@fromJSON: (objects) ->
return unless objects
if typeof objects is 'string'