Last active
August 29, 2015 14:00
-
-
Save kao/11282332 to your computer and use it in GitHub Desktop.
Example AngularJS controller in Coffeescript
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
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?() | |
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
'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'} | |
] |
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
'use strict' | |
angular.module('fauve') | |
.controller('TicketsController', [ | |
'$scope', | |
function ($scope) { | |
$scope.data = [ | |
{ id: 1, title: 'Hello', description: 'World' }, | |
{ id: 2, title: 'Bye', description: 'World'} | |
] | |
} | |
]); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Based on http://www.devign.me/angular-dot-js-coffeescript-controller-base-class