首页 > 解决方案 > AngularJS无法读取未定义的属性“路径”

问题描述

如果我的 vm.Question 为空但它不起作用,我想做的是转到其他页面,这是我的工作

(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);
        }
     }]);
})(); 

任何帮助都会很棒,谢谢

标签: angularjsroutinglocation

解决方案


$location在依赖注释中缺少,第 3 行:

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


推荐阅读