Created
March 18, 2012 19:17
-
-
Save ludicast/2079970 to your computer and use it in GitHub Desktop.
angular.coffee
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# in order to do this: | |
# <div ng:controller="MyController">{{message}}</div> | |
# I used to be able to | |
class MyController | |
constructor:-> | |
@message = "Hello World" | |
# Now I need: | |
class MyControllerWithScope | |
constructor:($scope)-> | |
$scope.message = "Hello World" | |
# But if you want original way you now can do | |
adaptForAngular(MyController) | |
-------------------- | |
adaptForAngular = (clazz, injections...)-> | |
injections.push "$scope" | |
@[clazz.name] = (args..., scope)-> | |
controller = new clazz() | |
angular.extend scope, controller | |
scope.initializeInjections? args... | |
scope.$scope = scope | |
@[clazz.name].$inject = injections |
petebacondarwin
commented
Mar 18, 2012
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment