【发布时间】:2018-01-05 02:11:14
【问题描述】:
我正在开发一个 angularjs 和 MVC 应用程序,我的应用程序运行良好,但我的控制台出现错误。
错误:$location:isrcharg
$location.search() 参数类型错误
$location#search()调用的第一个参数必须是字符串或对象
这是我的 angularjs 导航服务:
self.goBack = function () {
$window.history.back();
}
self.navigateTo = function (path, params) {
if (params === null) {
$location.path(MyApp.rootPath + path);
}
else {
$location.path(MyApp.rootPath + path).search(params);
}
};
self.refreshPage = function (path) {
$window.location.href = MyApp.rootPath + path;
};
self.clone = function (obj) {
return JSON.parse(JSON.stringify(obj))
};
self.querystring = function (param) {
if ($location.search !== null)
return $location.search()[param];
else
return null;
};
self.resetQueryParams = function () {
$location.url($location.path());
};
return this;
};
上面的代码是一个普通的工厂,所以在将它注入我的控制器之后,我就是这样导航的
在角度内我使用 viewModelHelper.navigateTo("/home");
然后如果我想导航到我使用的 mvc 页面
viewModelHelper.refreshPage("index");
当我在导航时,我在这段代码中遇到错误
$location.path(MyApp.rootPath + path).search(params);
【问题讨论】:
-
Error: $location:isrcharg。要解决此错误,请确保 $location.search 调用的第一个参数是字符串或对象。您可以使用与此错误关联的堆栈跟踪来识别导致此问题的调用站点。要了解更多信息,请参阅$location api 文档。
-
我猜是
params === undefined,代码正在检查params === null。 -
@geordeawg 看来你是对的,我确实在我的 navigateTo 方法上放了一个控制台日志......我的参数没有定义,但为什么它是导航......
-
我如何解决这个未定义的问题,我是 angular 新手
标签: angularjs asp.net-mvc angularjs-service angularjs-routing