我需要将参数传递给onclick
内通过ng-repeat
调用的函数:
<!-- Sliding bar (bottom) -->
<div ng-show="currentSVG && currentLanguage && currentWidth && bannerHeight" pageslide ps-open="bottomBar" ps-side="bottom" ps-speed="0.3" align="center">
<div id="related" class="content mThumbnailScroller" style="padding-top: 5px" ng-show="currentSVG && currentLanguage">
<ul>
<li ng-repeat="lastSVG in svgHistory track by $index">{{lastSVG}}<a href="javascript:void(0)" onclick="changeSVG({{lastSVG}})"><img src="../downloads/PNG/{{currentLanguage}}/{{lastSVG}}.png" width="{{currentWidth * 0.1}}" height="{{bannerHeight * 0.65}}" title="{{lastSVG}}" /></a></li>
</ul>
</div>
</div>
如何将参数lastSVG
提供给changeSVG()
中的onclick
功能?
changeSVG()
不在控制器中。如果我设置参数,它可以正常工作。
此外,它不适用于ng-click
而不是onclick
以下是changeSVG
功能:(该功能不在控制器中)
function changeSVG(svgName, defaultZoom){
if (!defaultZoom)
defaultZoom = 1;
var scope = angular.element(document.getElementById('container')).scope();
scope.currentSVG = svgName;
scope.currentZoom = defaultZoom;
if (scope.svgHistory.indexOf(svgName) === -1)
if (scope.svgHistory.unshift(svgName) > 20)
scope.svgHistory = scope.svgHistory.slice(0, 20);
localStorage.setItem("svgHistory", JSON.stringify(scope.svgHistory));
removeEmbed();
var svgPath = "../SVG/" + scope.currentLanguage + "/" + svgName + ".svg";
lastEmbed = createNewEmbed(svgPath, defaultZoom);
}
答案 0 :(得分:0)
没有大括号的ng-click指令应该可以解决问题:
<a href="javascript:void(0)" ng-click="changeSVG(lastSVG)">
ng-click指令将查找名为lastSVG的作用域上的任何属性并找到它(因为ng-repeat为每次重复创建一个新作用域)
一个有效的插件示例:
答案 1 :(得分:0)
好吧,我必须更改我的代码并在控制器内部创建功能才能使其正常工作。 但我仍然想知道如果我们想用控制器外部的功能来实现这一点。