gpt4 book ai didi

javascript - 无法在 ng-click 上获取 href 内容

转载 作者:行者123 更新时间:2023-11-27 22:33:03 25 4
gpt4 key购买 nike

我这里有这个元素:

<a href="#item1" ng-click="myfunc('arg1', 'arg2')">Item1</a>
<a href="#item2" ng-click="myfunc('arg1', 'arg2')">Item2</a>

“myfunc”需要 2 个传入参数。现在,我还需要一些别的东西,那就是 href-attribute 的内容。

我可以执行以下操作之一

1 - Add a new argument to the function
2 - Add the event argument to read the content of href-attribute

但是,在这个应用程序中似乎还有许多其他地方调用了函数“myfunc”。这意味着我需要修改它们以反射(reflect)新的参数列表。

所以我想知道 Controller 中是否有某种方式可以知道调用元素的 href 包含什么属性。这可能吗?

最佳答案

这里的问题是您将服务方法放入 Controller 中。将 myfunc 函数移至服务并向其添加 href 参数。然后从你的 Controller 和其他地方调用这个服务方法。

在您的 Controller 中,您可以通过以下方式获取 href:get original element from ng-click

在 myfunc 的其他调用中,您必须从不同的源获取 href。

关于javascript - 无法在 ng-click 上获取 href 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39391169/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com