Skip to content

Instantly share code, notes, and snippets.

View adickson311's full-sized avatar

Andre Dickson adickson311

View GitHub Profile
MultipleModelService.watchMultiple({
models: [
{ method: ReserveWishListModelProvider.getAll, as: 'reserveWishListItems'},
{ method: ReserveItemsModelProvider.getAll, as: 'reserveListItems'}
],
transformAs: 'fullReserveList',
// Concatenate wish list items and reserve items to create the full reserve wish list
transform: function buildReserveList(reserveWishItems, reserveItems) {
reserveWishItems = _.sortBy(reserveWishItems, function (i) {
return i.description.toLowerCase();
@adickson311
adickson311 / quickbooleans.js
Created May 29, 2015 15:24
Angular, quick booleans in templates
//
// Problem: In Angular, you're using directives in the HTML to reference properties on the scope,
// but you end up with super long expressions in your html like ...
//
// ng-if="myCity.publicZoo.myEscapedAnimal.type === animals.mammals.primates.orangutan"
//
// and you end up exposing constants to the scope so you can do those checks
//
// $scope.animals = Animals
//
@adickson311
adickson311 / gist:7cd33a9748502097d041
Last active August 29, 2015 14:21
Angular - Watch for key press on multiple form elements
// Route multiple form elements to a single method to handle key presses in Angular
//ng-keypress="checkKey($event)"
$scope.checkKey = function(e){
if(e.charCode === 13){ // 13 = Enter
switch(e.currentTarget.name){
case 'elementName':
$scope.doThing();
break;
case 'elementTwo':
@adickson311
adickson311 / noInput.js
Created February 5, 2015 19:07
Angular directive for preventing user input on a text input box, while allowing them to clear the field with delete.
myApp.directive('no-input', function() {
return {
restrict: 'A',
replace: false,
link: function(scope, el) {
el.on('keydown', function(e){
if(e.keyCode === 8){
el.val('');
el.trigger('change');
} else {
@adickson311
adickson311 / Months to Years
Last active December 22, 2015 06:19
This is a jQuery utility method I wrote that takes a number representing the number of months and returns a string representation of that number in years and months.
$.monthsToYears = function(months){
var val;
if(months < 12) {
val = months + ' month';
if(months > 1 || months === 0){
val += 's';
}
} else {
var yrs = Math.floor(months/12);
var mo = months%12;