0

I am a bit new to AngularJS and currently I am building a site to show questions to user. A view should contain a question and next button - by clicking which user should be shown next question.

For this, I created one ng-view (using angular-router module) and invoking the same view again and again by providing next question content.

But I can't invoke the view in which currently I already am.

I tried angular-ui-router - $stateProvider too but same issue.

Just wanted to ask is there anything wrong in my design? Or is this even possible in angular-route or angular-ui-router? If not possible then please let me know what are the alternate ways to do this?

Thanks very much for your time and response.

EDIT: Code snippets.

$stateProvider
    .state('question', {
        url: '/question',
        controller: 'questionCtrl',
        templateUrl: 'views/question.html'
    });

Start questions link:

<a ui-sref="question">Start questions</a>

Next question link:

<div><a ui-sref="question">Next Question</a></div>

Same goes for angular-route too, I had defined in proper way and used it to invoke properly.

Ketan
  • 738
  • 2
  • 9
  • 20
  • It is possible. But you're doing something wrong. But you didn't post any code so we can't tell you what, not how to fix it. – JB Nizet Aug 23 '15 at 09:27
  • Try it with `$routeProvider.when('/question/:next?', { ... });` then you can change the link to the next question by changing the corresponding scope variable. The param you can get by `$routeParams.next` ($routeParams need to be injected into the controller) – JSB Aug 23 '15 at 10:21
  • Your state should have a state parameter: the ID of the question you want to show. Something like `'/questions/:questionId'` – JB Nizet Aug 23 '15 at 10:22
  • Why do you even need the router? do you get the questions from a server? because if you do you can just update an object every time with the questions details and bind it to your DOM and that's it. – Yousef_Shamshoum Aug 23 '15 at 10:48
  • Actually I didn't want to expose the question number so I haven't done the params approach, sorry as I didn't mention in my question :). About other comment, yes I do get question from the server and I have already tried that and that's working by changing the content in DOM. But that doesn't allow me to back by clicking back browser button although I already have a previous question button. But that's the last resolve I will fall to if nothing else works out. – Ketan Aug 23 '15 at 11:36

0 Answers0