AngularJS 无法读取未定义的 属性 'path'
AngularJS Cannot read property 'path' of undefined
我想做的是在我的 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);
}
}]);
})();
任何帮助都会很棒,谢谢
您在依赖注释中缺少 $location
,第 3 行:
angular.module('mainApp').controller('question-template', ['dataContext', '$location', function (dataContext, $location) {
我想做的是在我的 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);
}
}]);
})();
任何帮助都会很棒,谢谢
您在依赖注释中缺少 $location
,第 3 行:
angular.module('mainApp').controller('question-template', ['dataContext', '$location', function (dataContext, $location) {