Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
# in order to do this:
# <div ng:controller="MyController">{{message}}</div>
# I used to be able to
class MyController
@message = "Hello World"
# Now I need:
class MyControllerWithScope
$scope.message = "Hello World"
# But if you want original way you now can do
adaptForAngular = (clazz, injections...)->
injections.push "$scope"
@[] = (args..., scope)->
controller = new clazz()
angular.extend scope, controller
scope.initializeInjections? args...
scope.$scope = scope
@[].$inject = injections
Copy link

petebacondarwin commented Mar 18, 2012

MyController = ($scope, $otherService)->
  someInternalField = "secret"

  someHiddenHelper = ()->
    #  I can use $scope and $otherService in here
    return $otherService.doStuff($scope.someField)

  $scope.someScopeHelper = ()->
    $scope.fieldToUpdate = someHiddenHelper()

  # I can initialize $scope here
  $scope.someField = "myValue"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment