angularjs - 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);
}
}]);
})();
任何帮助都会很棒,谢谢
解决方案
您$location
在依赖注释中缺少,第 3 行:
angular.module('mainApp').controller('question-template', ['dataContext', '$location', function (dataContext, $location) {
推荐阅读
- python-3.x - python3找不到newt库freebsd
- java - 为什么 Spring Boot 应用程序实体 ID 不会自动生成
- c# - 如何提取 XML 中错误的行号?
- c# - 在 c# 中将 Nested-GridView 与 DataSource DataTable 绑定
- kubeflow - 安装 kubeflow 失败
- spring-boot - 模拟 REST 客户端
- c# - 检查对象是否为默认值
- c++ - 用于模板类中的同名函数时,std::enable_if 会产生错误
- laravel - 为什么当我尝试在我的 laravel 应用程序上连接时,它总是连接到 base 中的最后一个条目?
- android - HMS 地理编码功能