0

what I am trying to do is to get to other page if my vm.Question is empty but it dose not work, here is my work

(function () {
'use strict';
angular.module('mainApp').controller('question-template', ['dataContext', function (dataContext, $location) {
    var vm = this;

    dataContext.getOneQuestion(sessionStorage.getItem("SavedString")).then(
        function (response) {
            vm.Question = response.data;
            if (vm.Question.length == 0) {
                $location.path("/noquestion"); <- HERE
                return;                 
            }
        },
        function (error) {
          console.log(error);
        }
     }]);
})(); 

Any help would be awesome, thank you

2
  • 3
    you didn't inject it correctly: ['dataContext', function (dataContext, $location), add '$location' Commented Aug 8, 2018 at 11:59
  • it worked! Thank you Commented Aug 8, 2018 at 12:01

1 Answer 1

1

You are missing $location in Dependency Annotation, line 3rd:

angular.module('mainApp').controller('question-template', ['dataContext', '$location', function (dataContext, $location) {

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.