$ location.search()["mode"]在angularjs中返回未定义 [英] $location.search()["mode"] returns undefined in angularjs

查看:35
本文介绍了$ location.search()["mode"]在angularjs中返回未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对angularjs比较陌生,并且遇到以下问题.我的网址看起来像:

I'm relatively new to angularjs and have the following problem. I have a url that looks like:

localhost:10001/Broadcast/New?mode=launchQL&ID=U1DboHfQVU65VYQ21t5nLw

在控制器内部,我试图根据参数mode和ID设置一些逻辑.

Inside my controller I'm trying to set some logic based on the parameters mode and ID.

myApp.controller('MyCtrl', function($scope, $http, $filter, $log, $timeout, $location){
$scope.mode = ($location.search())['mode'];
$scope.ID = ($location.search())['ID'];
}

我无法确定$ location.search()为什么不返回字典

I have not been able to determine why the $location.search() isn't returning the dictionary

{'mode':'launchQL', 'ID':'U1DboHfQVU65VYQ21t5nLw'}

如文档所述,如预期的那样.我不确定我在这里想念的是什么.任何帮助表示赞赏.预先感谢您的宝贵时间.

as expected like the documentation says. I'm not sure what I'm missing here. Any help is appreciated. Thanks in advance for your time.

推荐答案

这是因为在AngularJS中使用的东西必须位于hash(#)或hashbang(#!)之后.您现在拥有的url只是带有常规查询字符串的常规url.您需要的是AngularJS的Single Page Application(SPA)中的路由设置,该路由设置指向某个控制器.如果在常规路线后面提供了搜索变量,则可以从那里访问搜索变量.

This is because the things you use in AngularJS need to be behind an hash(#) or hashbang (#!). The url you have now is just a regular url with a regular querystring. What you want is a routing setup in your Single Page Application (SPA) in AngularJS that points to some controller. From there you can access the search variables if provides behind the normal route.

因此您的网址应如下所示:

So your url should look like:

localhost:10001/Broadcast/New#someroute?mode=launchQL&ID=U1DboHfQVU65VYQ21t5nLw

这篇关于$ location.search()["mode"]在angularjs中返回未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆