Created
March 13, 2012 21:09
-
-
Save petebacondarwin/2031617 to your computer and use it in GitHub Desktop.
Handlers in Angular Routes
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
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