Skip to content

Instantly share code, notes, and snippets.

@petebacondarwin
Created March 13, 2012 21:09
Show Gist options
  • Save petebacondarwin/2031617 to your computer and use it in GitHub Desktop.
Save petebacondarwin/2031617 to your computer and use it in GitHub Desktop.
Handlers in Angular Routes
angular.module('AppConfig',[])
.config(['$routeProvider', ($routeProvider)->
updateQuestionnaire = (scope, next)->
questionnaire = next.params.questionnaire ? ''
scope.$root.questionnaireId = questionnaire
updateQuestionnIndex = (scope, next)->
questionIndex = Number(next.params.questionIndex)
if questionIndex? and not isNaN(questionIndex)
scope.$root.questionIndex = questionIndex
else
next.redirectTo = '/'
$routeProvider.when('/:questionnaire/:questionIndex',
template: '/templates/question.html'
handler: (scope, next)=>
updateQuestionnaire(scope, next)
updateQuestionnIndex(scope, next)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment