更改视图和控制器,而无需更新网址或历史记录 [英] Change view and controller without updating url or history

查看:133
本文介绍了更改视图和控制器,而无需更新网址或历史记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建使用Angularjs问答游戏,有三个布局。一个用于介绍,问题和奖金的问题。我想在不改变URL或历史,因为用户不能回去改变他们的回答来创建它。这是可能的,或者我应该尝试这样做在同样的路线,控制器和视图,显示隐藏的布局。

I am creating a quiz game using Angularjs, there are three layouts. One for intro, question and bonus questions. I am trying to create it without changing the url or history since users are not allowed to go back and change their answer. Is this possible or should I be trying to do this in the same route, controller and view, show hiding layouts.

或是否有更好的方式来做到这一点。

or is there a better way to accomplish this.

先谢谢了。

推荐答案

您可以使用 ngInclude https://docs.angularjs.org/api/ng/directive/ngInclude )根据测验进度而变化的模板,请参阅样本演示在这里
http://plnkr.co/edit/jq63ULx2ZrRC9rbJJzOY?p=$p$pview

You can use ngInclude (https://docs.angularjs.org/api/ng/directive/ngInclude) to change template according to quiz progress, please see sample demo here http://plnkr.co/edit/jq63ULx2ZrRC9rbJJzOY?p=preview

<body ng-controller="MainCtrl">   
    <a href="" ng-click="next()">Next Question</a>
    <hr/>
    <div ng-include="template"></div>
</body>

JS:

var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope) {
    $scope.name = 'World';
    $scope.q = 1;
    $scope.template = "view1.html";
    $scope.next = function() {
        if ($scope.q < 4) {
            $scope.q++;
            $scope.template = "view" + $scope.q + ".html";
        }
    }
});

这篇关于更改视图和控制器,而无需更新网址或历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆