为什么我不能将角度变量作为函数参数传递?

时间:2021-10-04 00:37:10

I'm trying to pass the follower through the followPerson() function. This works fine if I do followPerson(123). But when I do followPerson({{follower.follower}}) it doesn't fire.

我试图通过followPerson()函数传递跟随者。如果我关注角色(123),这可以正常工作。但是,当我跟随角色({{follower.follower}})时,它不会发射。

{{follower.follower}} definitely works as it's shown in bold.

{{follower.follower}}绝对有效,因为它以粗体显示。

<div ng-repeat="follower in followers.followers">
    <b>{{follower.follower}}</b>
    <a ng-click="followPerson({{follower.follower}})">Follow</a> 
</div>

1 个解决方案

#1


6  

You must not use interpolation ({{) for the arguments in the ng-click handler, it will just result in a parse error (If not using very old angular versions) due to invalid expression. You just need to pass the argument expression as is, angular will just evaluate is against the scope while evaluating the ng-click handler.

您不能对ng-click处理程序中的参数使用插值({{),由于表达式无效,它只会导致解析错误(如果不使用非常旧的角度版本)。您只需要按原样传递参数表达式,在评估ng-click处理程序时,angular将仅对范围进行求值。

Just do:

做就是了:

 ng-click="followPerson(follower.follower)"

Have a look at your console for errors.

看看你的控制台是否有错误。

#1


6  

You must not use interpolation ({{) for the arguments in the ng-click handler, it will just result in a parse error (If not using very old angular versions) due to invalid expression. You just need to pass the argument expression as is, angular will just evaluate is against the scope while evaluating the ng-click handler.

您不能对ng-click处理程序中的参数使用插值({{),由于表达式无效,它只会导致解析错误(如果不使用非常旧的角度版本)。您只需要按原样传递参数表达式,在评估ng-click处理程序时,angular将仅对范围进行求值。

Just do:

做就是了:

 ng-click="followPerson(follower.follower)"

Have a look at your console for errors.

看看你的控制台是否有错误。