Thursday 15 August 2013

angularjs - Change view and controller without updating url or history -



angularjs - Change view and controller without updating url or history -

i creating quiz game using angularjs, there 3 layouts. 1 intro, question , bonus questions. trying create without changing url or history since users not allowed go , alter answer. possible or should trying in same route, controller , view, show hiding layouts.

or there improve way accomplish this.

thanks in advance.

you can utilize nginclude (https://docs.angularjs.org/api/ng/directive/nginclude) alter template according 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"; } } });

angularjs

No comments:

Post a Comment