谁能帮我集成状态机来控制路由?
最好的方法是什么?创建服务?
我需要基本上拦截每个 $location 请求,运行状态机并让它找出下一个 $location.path 应该是什么。
把这个问题想象成一堆随着时间的推移而被添加和删除的问题。用户偶尔访问一次,将用户的答案对象传递给状态机,状态机确定要加载哪个问题。这是我的伪代码,但我需要弄清楚把它放在哪里或者我可以挂钩什么事件,以确保所有路由请求都通过机器。我需要特定的 stateMachine 控制器吗?我要创建服务吗?我在哪里使用该服务?我需要覆盖 $locationProvider 吗?
$scope.user.answers = [{
id: 32,
answer: "whatever"
},
{
id:33,
answer: "another answer"
}]
$scope.questions = [{
id:32,
question:"what is your name?",
path:"/question/1"
},{
id:34,
question:"how old are you?",
path:"/question/2"
}]
var questions = $scope.questions;
angular.forEach(questions, function(question) {
if(question.id !exist in $scope.user.answers.id) {
$location.path = question.path
break;
});
谢谢