使用 $routeParams 或 $location 作为历史链接
Using $routeParams or $location for History Links
我正在做一个问题库,我已经很好地编写了大部分元素的代码,但我想添加一些浏览器历史记录来浏览问题。
下面是 plunker 的基本设置:
http://embed.plnkr.co/1F64dDrxVYfD8ScVGgac/preview
当前页面加载速度低于 /quiz
但我想 $scope.currentQ
通过
的 url 搜索动态更改
/quiz?q=1
我试过 $routeParams 作为替代方案和 $location 但我似乎无法让它正常工作。有人可以帮帮我吗?
// 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 is it?",
choices: [
"2011",
"2012",
"2013",
"2014",
"2015"
],
answer: "2015",
reason: "Because it is not yet 2016!",
category: "test"
}, {
questionid: 2,
question: "Which medical school is the best?",
choices: [
"Kings",
"Imperial",
"St. George's",
"Barts",
"UCL"
],
answer: "UCL",
reason: "Creators are from UCL, do I need to say any more?",
category: "test2"
}];
})();
这是一个基于 $location 服务的导航示例 http://run.plnkr.co/50SiWpwg1VEvLo2w/?q=1 (link to code http://plnkr.co/edit/PZX9Td4y6EJEnLm2yK4H?p=preview)。这是根据此事件进行导航的最简单方法:
$scope.$on('$locationChangeSuccess', function() {...})
我正在做一个问题库,我已经很好地编写了大部分元素的代码,但我想添加一些浏览器历史记录来浏览问题。
下面是 plunker 的基本设置: http://embed.plnkr.co/1F64dDrxVYfD8ScVGgac/preview
当前页面加载速度低于 /quiz
但我想 $scope.currentQ
通过
/quiz?q=1
我试过 $routeParams 作为替代方案和 $location 但我似乎无法让它正常工作。有人可以帮帮我吗?
// 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 is it?",
choices: [
"2011",
"2012",
"2013",
"2014",
"2015"
],
answer: "2015",
reason: "Because it is not yet 2016!",
category: "test"
}, {
questionid: 2,
question: "Which medical school is the best?",
choices: [
"Kings",
"Imperial",
"St. George's",
"Barts",
"UCL"
],
answer: "UCL",
reason: "Creators are from UCL, do I need to say any more?",
category: "test2"
}];
})();
这是一个基于 $location 服务的导航示例 http://run.plnkr.co/50SiWpwg1VEvLo2w/?q=1 (link to code http://plnkr.co/edit/PZX9Td4y6EJEnLm2yK4H?p=preview)。这是根据此事件进行导航的最简单方法:
$scope.$on('$locationChangeSuccess', function() {...})