JSFiddle

  • Mocking $sessionStorage for controller testing

    No-Library (pure JS), HTML, CSS, JavaScript

    // CODE
    (function (angular) {
        
        'use strict';
        
        function MyController($sessionStorage) {
        
            var vm = this;
            
            vm.notifications = {
    			      someData: $sessionStorage.get('someData')
            };
            
            vm.updateData = function ...
  • Mocking $sessionStorage for controller testing

    No-Library (pure JS), HTML, CSS, JavaScript

    // CODE
    (function (angular) {
        
        'use strict';
        
        function MyController($sessionStorage) {
        
            var vm = this;
            
            vm.notifications = {
    			      someData: $sessionStorage.get('someData')
            };
            
            vm.updateData = function ...
  • ngEgg Demo #10 is the latest revision

    Demonstration of ngEgg by Scriptwerx.

    /**
     * angular-egg - An AngularJS Directive implementation of egg.js by Mike Flynn
     * @author Paul Massey, paul.massey@scriptwerx.io
     * @version v0 ...
  • Fraction size for AngularJS 1.2.x currency filter. #12 is the latest revision

    AngularJS 1.2.1, HTML, CSS, JavaScript

    (function (angular) {
        angular.module('test', [])
            .config(config)
            .controller('TestController', TestController);
    
        function config($provide) {
    
            function currencyFilter($delegate, numberFilter) {
    
                return function (amount ...
  • Smallest or largest value form Array

    No-Library (pure JS), HTML, CSS, JavaScript

    // Short way to get the smallest & largest values from Arrays
    var testArr = [2, 1, 7, 9, 4];
    
    function smallestValue(arr) {
        return Math.min.apply(Math, arr);
    }
    
    function largestValue(arr) {
        return Math ...
  • AngularJS - Currency formatted input #113 is the latest revision

    AngularJS 1.2.1, HTML, CSS, JavaScript

    (function () {
    
        'use strict';
    
        function TestController() {
    
            var test = this;
    
            test.money = 100000;
    
            test.randomMoney = function () {
                test.money = Math.random() * 100000;
            };
        }
    
        function ...
  • AngularJS Table Demo #10 is the latest revision

    Demo to show how to create table with dynamic rows and columns based on user input.

    /**
    * This was in response to a question that came up on a forum
    */
    
    // myApp.js
    (function() {
        
        'use strict';
        
        function config ...
  • window.localStorage polyfill #18 is the latest revision

    Check for localStorage support and fall back to simple session storage. At time of writing 89% of browsers support localStorage so falling back to cookie is unnecessary.

    /**
     * @description Check for localStorage support and fall back to simple session storage.
     * At time of writing 89% of browsers support ...
  • Sort an Array of Objects #14 is the latest revision

    Quick demo on how to sort an Array of Objects by key.

    (function () {
    
        'use strict';
        
        var unsorted = [{
            name: 'Peter',
            age: 35
        }, {
            name: 'John',
            age: 34
        }, {
            name: 'Jess',
            age: 46
        }, {
            name: 'Alice',
            age ...