Monthly Archives: December 2014

AngularJS Custom Dropdown Time Filter

I’ve created this filter to allow hour selection using HTML dropdown. The filter accepts as input three paramers: the starting hour, the ending hour, and the minute interval. var app = angular.module(‘APP’, [‘APP.filters’]); app.controller(‘MainController’, [‘$scope’, function($scope) { }]); angular.module(‘APP.filters’, []).filter(‘time’, function() { return function(input, from, to, interval) { from = parseInt(from, 10); to = parseInt(to, Continue Reading »

AngularJS Cookie Service

In case you’re searching for a cookie service that can be used in AngularJS, here it is:   ‘use strict’ angular .module(‘APP.services’, []) .factory(‘Cookie’, function() { var self = this; self.set = function(name, value, days) { var expires = “”; if(days) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); expires = “; expires=”+date.toGMTString(); } else { Continue Reading »

Load Google Maps Library on the fly

Define the service: ‘use strict’; angular .module(‘APP.services’) .factory(‘GMAPS’, [‘$window’, function($window) { var self = this, callback = null; $window.gmaps_loaded = function() { if(callback) { callback(); } }; self.load = function(cb) { if($window.google) { cb(); return; } callback = cb; var gmaps_script = $window.document.createElement(‘script’); gmaps_script.type = ‘text/javascript’; gmaps_script.src = ‘https://maps.googleapis.com/maps/api/js?v=3.exp&callback=gmaps_loaded&client=your_client_id’; $window.document.body.appendChild(gmaps_script); }; return { ‘load’: self.load Continue Reading »