Skip to content

Instantly share code, notes, and snippets.

@roparz roparz/routes.coffee
Last active Aug 29, 2015

Embed
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) ->
MyService.do()
]
# after
$stateProvider.state 'app',
controller: _build ($state, $stateParams, MyService) ->
MyService.do()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.