Skip to content

Instantly share code, notes, and snippets.

@kao
Last active August 29, 2015 14:00
Show Gist options
  • Save kao/11282332 to your computer and use it in GitHub Desktop.
Save kao/11282332 to your computer and use it in GitHub Desktop.
Example AngularJS controller in Coffeescript
class @Base
@inject: (args...) ->
if args.length is 1
args = args[0].split ' '
if @$inject?.length > 0
for arg in args
@$inject.push arg
else
@$inject = args
@register: (app, type, name) ->
app[type] name, @
constructor: (args...) ->
for key, index in @constructor.$inject
@[key] = args[index]
@initialize?()
'use strict'
class TicketsController extends Base
@register angular.module('fauve'), 'controller', 'TicketsController'
@inject '$scope'
initialize: ->
@$scope.data = [
{ id: 1, title: 'Hello', description: 'World' },
{ id: 2, title: 'Bye', description: 'World'}
]
'use strict'
angular.module('fauve')
.controller('TicketsController', [
'$scope',
function ($scope) {
$scope.data = [
{ id: 1, title: 'Hello', description: 'World' },
{ id: 2, title: 'Bye', description: 'World'}
]
}
]);
@kao
Copy link
Author

kao commented Apr 25, 2014

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