0

I'm really new to AngularJs and I can't find how to do the following :

A user is answering questions in a quiz.html page. Each answer is added to a "answers" list. In a controller I want to redirect to a result.html page if my "answers" list contains 4 answers...

if (answers.length === 4) {
    ???? }

I know this is a simple question but I can't find any simple answer Thank you !

4
  • possible duplicate of Difference between angular-route and angular-ui-router Commented Mar 4, 2015 at 22:02
  • What routing solution are you using? Commented Mar 4, 2015 at 22:03
  • Not really a duplicate though, but look into ngRoute. Commented Mar 4, 2015 at 22:03
  • I'm using the ionic framework so I guess i'm using ui-router ? Commented Mar 4, 2015 at 22:09

2 Answers 2

1

You can use Angular $location

if (answers.length === 'whatever') {
    $location.path("/result")
}

In your app.js

$routeProvider.when('/result', {
    templateUrl: 'templates/result.html',
        controller: 'ResultCtrl'
    })...

Make sure to inject the $location into your controller.

Sign up to request clarification or add additional context in comments.

Comments

0

You could attach a ng-click when a user clicks, so in your controller you would have,

$scope.checkAnswerLength = function(){
    if (answers.length === 4) {
        $location.path("/result")
    }
}

Then in HTML add on click checkAnswerLength, and if the answers length is 4 it will redirect to route /result

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.