javascript - Using $routeParams or $location for History Links -
i working on questionbank , have nicely coded of elements, add browser history navigating questions.
so here basic setup on plunker: http://embed.plnkr.co/1f64ddrxvyfd8scvggac/preview
currently page loads under /quiz
$scope.currentq
dynamically changed url search of
/quiz?q=1
i have played around $routeparams alternative , $location can't seem work properly. can give me helping hand?
// code goes here (function() { 'use strict'; var app = angular.module('questionbank', []); ////////////// //directives// ////////////// app.controller('questionbankcontroller', ['$scope', function($scope) { $scope.currentq = 0; $scope.guess = []; $scope.sbachoices = ['a', 'b', 'c', 'd', 'e']; $scope.questions = questions; $scope.prevq = function() { if ($scope.currentq !== 0) { $scope.currentq--; } }; $scope.nextq = function() { if ($scope.currentq < $scope.questions.length - 1) { $scope.currentq++; } }; $scope.submit = function(guess) { }; }]); var questions = [{ questionid: 1, question: "what year it?", choices: [ "2011", "2012", "2013", "2014", "2015" ], answer: "2015", reason: "because not yet 2016!", category: "test" }, { questionid: 2, question: "which medical school best?", choices: [ "kings", "imperial", "st. george's", "barts", "ucl" ], answer: "ucl", reason: "creators ucl, need more?", category: "test2" }]; })();
here example navigation based on $location service http://run.plnkr.co/50siwpwg1vevlo2w/?q=1 (link code http://plnkr.co/edit/pzx9td4y6ejenlm2yk4h?p=preview). it's simplest way have navigation working based on event:
$scope.$on('$locationchangesuccess', function() {...})
Comments
Post a Comment