gpt4 book ai didi

javascript - 在 ng-click 中传递变量

转载 作者:行者123 更新时间:2023-11-29 16:59:05 26 4
gpt4 key购买 nike

我在范围内有变量 $id。我想将它传递给函数“createPNG”,在这个函数中我想使用这个 ID 来访问 downloadContainer。

<button type="button" ng-click="createPNG('{{$id}}')">Create Image</button>
<div ng-attr-id="downloadContainer_{{$id}}"></div>

Angular 正确地将 downloadContainer_{{$id}} 转换为正确的数字,但该函数仅传递字符串 {{$id}}。在旧的 angularJS 版本中我没有这个问题。

最佳答案

只需替换为

<button type="button" ng-click="createPNG($id)">Create Image</button>

关于javascript - 在 ng-click 中传递变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29766407/

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