Angularjs 将查询字符串参数从html发送到angular指令

Angularjs 将查询字符串参数从html发送到angular指令,angularjs,Angularjs,我编写了一个angular指令,需要从查询字符串中向他发送一些值 例如: 角度模块('TESTTTT',[]) .directive('ngSomeDirective',函数(){ 返回{ 限制:'E', 范围:{ 测试:'@' }, templateUrl:“/someurl.html”, 链接:函数(范围、元素、属性){ var acc=范围$eval(属性测试); }, } }) 使用“=”进行表达式绑定:- scope: { test: '='

我编写了一个angular指令,需要从查询字符串中向他发送一些值

例如:

角度模块('TESTTTT',[]) .directive('ngSomeDirective',函数(){ 返回{ 限制:'E', 范围:{ 测试:'@' }, templateUrl:“/someurl.html”, 链接:函数(范围、元素、属性){ var acc=范围$eval(属性测试); }, } })
使用“=”进行表达式绑定:-

scope: {
              test: '='
          }

你的问题类似于

如果要在视图中使用
test=“$location.search().keu;”
,请将范围变量定义为

scope: {
  test: '='
}
如果你还想用

scope: {
  test: '@'
}
您应该将视图更改为
test=“{{$location.search().keu;“}}


最后但并非最不重要的一点是,在您喜欢的阶段,通过
scope.test

访问测试对象。您好,感谢您的响应,我将更改为{{$location.search().keu},并且我总是得到一个空字符串。我是否需要在控制器上声明某些内容?您需要将$location注入控制器并将其作为$scope绑定到作用域。$location=$LocationThank。我将这一行添加到我的控制器:函数testCtrl($scope,$http,$location){$scope.$location=$location;这一行添加到default.html这是url:并且我仍然得到一个ampty字符串。你能试一下控制台日志
$location.search()吗
要查看输出是什么?现在我们知道当前问题与数据绑定无关,因为
$location.search()
为空,您需要尝试找出
$location.search()
无法获取当前URL的搜索部分的原因。