Skip to content

Instantly share code, notes, and snippets.



Last active Aug 29, 2015
What would you like to do?
AngularJS route builder that avoid declaration duplication
_build = (callback) ->
string = callback.toString()
mathes = string.match /function\s?\(([\w,\s?\$]+)\)\s?\{/
arr = mathes[1].split(', ')
arr.push callback
return arr
# using AngularUI Router
angular.module('app').config ($stateProvider) ->
# before
$stateProvider.state 'app.old',
controller: ['$state', '$stateParams', 'MyService', ($state, $stateParams, MyService) ->
# after
$stateProvider.state 'app',
controller: _build ($state, $stateParams, MyService) ->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment