Skip to content

Instantly share code, notes, and snippets.

@8bitDesigner
Last active August 29, 2015 14:02
Show Gist options
  • Select an option

  • Save 8bitDesigner/09c025a0a260f53dbfa0 to your computer and use it in GitHub Desktop.

Select an option

Save 8bitDesigner/09c025a0a260f53dbfa0 to your computer and use it in GitHub Desktop.
class Controller
constructor: ($injector) ->
@init.apply(@, @injectables.map((val) -> $injector.get(val)))
$injector.get('$scope').$on, '$destroy' => @deinit()
class MyController extends Controller
injectables: '$scope', '$modal'
init: ($scope, $modal) ->
@modal = $modal.open($scope.new())
@unwatch = $scope.$watch 'foo', @updateFoo
updateFoo: (newval) ->
@foo = newval * 2
deinit: ->
@modal.close()
@unwatch()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment