Skip to content

Instantly share code, notes, and snippets.

@ada-lovecraft
Last active December 25, 2015 19:59
Show Gist options
  • Save ada-lovecraft/7031158 to your computer and use it in GitHub Desktop.
Save ada-lovecraft/7031158 to your computer and use it in GitHub Desktop.
Invoking an AbstractController
app = angular.module('app')
AbstractController = ($scope) ->
$scope.namespace = 'abstract' unless $scope.namespace
# to save you a lot of typing...
namespace = $scope[$scope.namespace];
namespace.setup = (value) ->
namespace.setupComplete = true
namespace.x = value
AbstractController.$inject = ['$scope']
app.controller 'FooController', ($scope, $injector, $log) ->
$scope.namespace = 'foo';
$injector.invoke AbstractController, this, {$scope: $scope}
#to save you a lot of typing...
namespace = $scope[$scope.namespace];
namespace.setup('bar')
$log.log namespace.x
# 'bar'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment