-
-
Save davej/8198036 to your computer and use it in GitHub Desktop.
This file contains 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
define [ | |
'base-ctrl' | |
], (BaseCtrl) -> | |
class AppController extends BaseCtrl | |
@register() | |
@inject('$scope') | |
init: -> | |
@$scope.foo = "bar" |
This file contains 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
define [ | |
'config' | |
'angular' | |
'lodash' | |
], (cfg, A, _) -> | |
class @BaseCtrl | |
@parseFnName: -> | |
# Parses the class name manually from the string of the function definition. | |
# We only do this if we are using a version of Coffeescript that doesn't have | |
# the function name defined on the `.name` attribute. | |
/\W*function\s+([\w\$]+)\(/.exec(@)[1] | |
@register: (name) -> | |
app = A.module cfg.ngApp | |
app.controller name || @name || @parseFnName(), @ | |
@inject: (args...) -> | |
@$inject = args | |
constructor: (args...) -> | |
for key, index in @constructor.$inject | |
@[key] = args[index] | |
for key, fn of @constructor.prototype | |
continue unless typeof fn is 'function' | |
continue if key in ['constructor', 'init'] or key[0] is '_' | |
@$scope[key] = @constructor.prototype[key] = fn.bind?(@) || _.bind(fn, @) | |
@init?() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment