JSFiddle

  • 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 ...
  • 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 ...
  • Angular Extend #12 is the latest revision

    Using Angular extend for reusable code/inheritance

    (function (app) {
    
        var baseOData = {
            $http: {},
            $q: {},
            baseUrl: 'http://services.odata.org/V4/OData/OData.svc/',
            entity: '',
            get: function () {
                var defer ...
  • JavaScript Canvas Plasma

    Example of Plasma effect in JavaScript

    (function (c) {
        var ctx = c.getContext('2d'),
            palette = [],
            sine = [],
            width = c.clientWidth,
            height = c.clientHeight,
            pos1 = 0,
            pos3 = 0,
            tpos1 ...
  • Count Angular Watches

    Example module that counts watchers in your Angular app.

    (function (w) {
    
        function Service () {       
        }
        
        angular.extend(Service.prototype, {
            watchCount: 0,
            elem: {},
            countWatches: function () {
                
                var _this = this, scopeList = {};
                this.watchCount = 0 ...
  • How to $get Angular DI

    Example of how Angular DI works under the covers.

    (function () {
    
        'use strict';
    
        function MakeConstructorProvider(fn) {
            return {
                $get: function () {
                    function Template() {}
                    Template.prototype = fn.prototype;
                    return new Template();
                }
            };
        }
    
        function HelloWorld ...
  • Angular Feed Reader #8 is the latest revision

    An example of a feed reader built in Angular.

    (function (app) {
        
        function Service ($http, $q) {
            this.$http = $http; 
            this.$q = $q;
        }
        
        Service.$inject = [ "$http", "$q"];
        
        Service.prototype.loadFeed = function ...