Skip to content

Instantly share code, notes, and snippets.

Avatar

Pete Bacon Darwin petebacondarwin

View GitHub Profile
View class-decorators.md

@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 Nov 25, 2015
AngularJS issue 13374
View index.html
<!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 Oct 12, 2015
ngUpgrade vanilla Angular 1 example
View index.html
<!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 Oct 11, 2012 — forked from ggoodman/app.js
AngularJS@1.0.2 + Jasmine
View app.js
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.name = 'World';
});
@petebacondarwin
petebacondarwin / index.html
Created Mar 27, 2012
AngularJS 1.0 - Masked Input Widget
View index.html
<input ng-model="contact.phone" ui-mask='"(9999) 9999 9999"' placeholder="(01234)-5678-8901" required />
View gist:2170671
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 Mar 13, 2012
Handlers in Angular Routes
View app.coffee
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
View gist:2003785
###
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: ()=>
View app.js
var oldModelValue, newModelValue, counter;
function watchModelFn(scope) {
newModelValue = ngModelGet(scope);
if (
!updatingFromTheView &&
!(newModelValue === undefined && $valid === false) &&
!modelEquals(newModelValue, oldModelValue)
) {
View survey.coffee
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'