如何检查URL是否包含ID? [英] How to Check whether the URL contains Id or not?
本文介绍了如何检查URL是否包含ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
示例:我想检查url是否包含id,然后调用abc()函数,否则调用def()函数.
Example : i want to check if url contains id then call abc() function otherwise call def() function.
在使用mvc架构的angularjs中.
in angularjs using mvc architecture.
推荐答案
您可以使用它.
var url = $location.absUrl();
if(url.indexOf('id') !== -1){
//call abc()
}
或者
var url = $location.absUrl();
if(url.indexOf('id') < 0){
//call abc()
}
还要在控制器中注入$ location.另一个选择:使用window.location.href
Also inject $location in your controller. Another option: Use window.location.href
这篇关于如何检查URL是否包含ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文