JSFiddle

  • Constants #2 is the latest revision

    Make a constant value

    (function () {
        
        function makeConstant(name, val) {
        
            var x = val; 
            Object.defineProperty(window, name, {
                enumerable: true,
                configurable: false, 
                get: function () {
                    return x ...
  • Tools: AngularJS: From a Different Angle

    Example from AngularJS Talk

    (function () {
    
        var myApp = angular.module('myApp', []);
        baseService = {
            baseUrl: 'http://services.odata.org/V4/OData/OData.svc/Products',
            get: function () {
                var ...
  • Templates: AngularJS: From a Different Angle

    Example from AngularJS Talk

    (function () {
    
        var jeremy = {
            name: 'Jeremy Likness',
            age: 40
        },
        doreen = {
            name: 'Doreen Likness',
            age: 'Not polite to ask'
        },
        people = [jeremy, doreen ...
  • Container: AngularJS: From a Different Angle

    Example from AngularJS Talk

    (function () {
    
        var jeremy = {
            name: 'Jeremy Likness',
            age: 40
        },
        doreen = {
            name: 'Doreen Likness',
            age: 'Not polite to ask'
        },
        people = [jeremy, doreen ...
  • Glue: AngularJS: From a Different Angle

    Example from AngularJS Talk

    (function () {
        
        var person = { name: 'Jeremy Likness', age: 40 };
        
        angular.module('myApp', [])
        .run(['$rootScope', function ($rootScope) {
            $rootScope.jeremy = person;
        }]);
              
    })();
  • Expressions: AngularJS: From a Different Angle

    Example from AngularJS Talk

    (function () {
        angular.module('myApp', []);
    })();
  • AngularJS External Injector #2 is the latest revision

    Grab the injector outside of Angular

    (function (app) {
        
        function clicked() {
            var i = angular.injector(['myApp', 'ng']);
            i.get('$log').log('Clicked!');
        }
        
        document.getElementById('btnClick').addEventListener('click ...
  • AngularJS Deferred Creation

    Using $injector to wire up dependencies for objects introduced after initialization

    (function (app) {
    
        app.run(['$rootScope', '$injector', function (rs, i) {
            rs.click = function () {
                var myFunc = ['$log', function ($log) {
                    $log.log('This ...
  • AngularJS Lifetime Management #1 is the latest revision

    Using $injector for lifetime management

    (function (app) {
        
        function Counter ($log) {
            $log.log('Counter created.');
        }
        
        angular.extend(Counter.prototype, {
            count: 0,
            increment: function () {
                this.count += 1 ...
  • AngularJS Lazy-Loading

    Using $injector for lazy-loading

    (function (app) {
        app.config(['$provide', function ($provide) {
            $provide.decorator('$log', ['$delegate', '$injector', function ($delegate, $injector) {
                var log = $delegate.log.bind ...