CONCAT范围内的变量为字符串角指令前presssion [英] concat scope variables into string in angular directive expresssion

查看:143
本文介绍了CONCAT范围内的变量为字符串角指令前presssion的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在像这样的角度NG-点击指令使用范围的方法:

I am using a scope method in an angular ng-click directive like so:

<a ng-click="$navigate.go('#/path/obj.val1/obj.val2')">{{obj.val1}}, {{obj.val2}}</a>

这里的问题是,obj.val1和obj.val2是PTED为传递到前pression方法字符串的一部分际$ P $。我需要的变量,他们是......我不知道正确的方法是什么在这里他们进行评估。

The trouble here is that obj.val1 and obj.val2 are interpreted as part of the string passed to the method in the expression. I need them to be evaluated as the variables that they are... I'm not sure what the right approach is here.

有没有Concat的这些价值成字符串/ EX pression角度的方式?

Is there an angular way to concat these values into that string/expression?

是我只是做错了?

推荐答案

这不是很清楚你正试图从code你发布到完成的问题是什么,但我会在它采取刺伤。

It's not very clear what the problem is and what you are trying to accomplish from the code you posted, but I'll take a stab at it.

在一般情况下,我建议调用函数NG单击像这样:

In general, I suggest calling a function on ng-click like so:

<a ng-click="navigateToPath()">click me</a>

obj.val1 &安培; obj.val2 应可在控制器的$范围,你不需要传递到那些从标记的功能。

obj.val1 & obj.val2 should be available on your controller's $scope, you dont need to pass those into a function from the markup.

那么,在你的控制器:

$scope.navigateToPath = function(){
   var path = '/somePath/' + $scope.obj.val1 + '/' + $scope.obj.val2; //dont need the '#'
   $location.path(path)       
}

这篇关于CONCAT范围内的变量为字符串角指令前presssion的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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