Angularjs “$location#search()”调用的第一个参数必须是字符串或对象
我正在使用angularjs和MVC应用程序,我的应用程序运行良好,但我的控制台出现了一个错误 错误:$location:isrcharg 错误的$location.search()参数类型Angularjs “$location#search()”调用的第一个参数必须是字符串或对象,angularjs,asp.net-mvc,angularjs-service,angularjs-routing,Angularjs,Asp.net Mvc,Angularjs Service,Angularjs Routing,我正在使用angularjs和MVC应用程序,我的应用程序运行良好,但我的控制台出现了一个错误 错误:$location:isrcharg 错误的$location.search()参数类型 $location#search()调用的第一个参数必须是字符串或对象 这是我的angularjs导航服务: self.goBack = function () { $window.history.back(); } self.navigateTo = function
$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");
当im导航到时,此代码中出现错误
$location.path(MyApp.rootPath + path).search(params);
我的参数没有定义。如何解决这个未定义的问题
或
在上面的示例中,如果params
变量为空,则代码将仅执行.search
方法
在JavaScript中,值是在布尔上下文中计算时被视为true
的值。除非将所有值定义为(即,false
、0
、”
、null
、未定义的和NaN
),否则所有值均为空
有关详细信息,请参阅
我的参数没有定义。如何解决这个未定义的问题
或
在上面的示例中,如果params
变量为空,则代码将仅执行.search
方法
在JavaScript中,值是在布尔上下文中计算时被视为true
的值。除非将所有值定义为(即,false
、0
、”
、null
、未定义的和NaN
),否则所有值均为空
有关详细信息,请参见。要解决此错误,请确保$location.search调用的第一个参数是字符串或对象。您可以使用与此错误关联的堆栈跟踪来标识导致此问题的调用站点。要了解更多信息,请查阅文档。我的猜测是params===undefined
,代码正在检查params===null
@geordeawg。似乎你是对的,我确实在我的navigateTo方法上放了一个控制台日志。。。我的参数没有定义,但为什么它是导航的呢..我怎么解决这个未定义的问题呢,我是个新手。要解决此错误,请确保$location.search调用的第一个参数是字符串或对象。您可以使用与此错误关联的堆栈跟踪来标识导致此问题的调用站点。要了解更多信息,请查阅文档。我的猜测是params===undefined
,代码正在检查params===null
@geordeawg。似乎你是对的,我确实在我的navigateTo方法上放了一个控制台日志。。。我的参数没有定义,但为什么它是导航的呢..我是个新手,怎么解决这个未定义的问题呢
self.navigateTo = function (path, params) {
if ( ̶p̶a̶r̶a̶m̶s̶ ̶=̶=̶=̶ ̶n̶u̶l̶l̶ !params) {
$location.path(MyApp.rootPath + path);
}
else {
$location.path(MyApp.rootPath + path).search(params);
}
};
self.navigateTo = function (path, params) {
if (params) {
$location.path(MyApp.rootPath + path).search(params);
}
else {
$location.path(MyApp.rootPath + path);
}
};