角1.5
在ng-repeat中,我创建了一个按钮,该按钮将显示带有锚链接的Bootstrap popup。
如何绑定onAction调用,以便它调用我的$scope.onAction()函数?(onAction()不绑定到$scope.onAction())。
<div ng-repeat="item in model.Holdings track by $index" bs-popover>
<button class="popoverBtn"
data-content="<a ng-click='onAction(1)'>Buy</a>...and more"
click me to show popup
</button>
</div>下面是我的指令,打开Bootstrap弹出器:
app.directive('bsPopover', function () {
return function (scope, element, attrs) {
element.find(".popoverBtn").popover({ placement: 'auto', html: 'true' });
????COMPILE GOES HERE???////
};
});发布于 2017-03-06 20:04:26
听起来,您希望onAction方法接受一个项标识符。
也许像<a ng-click='onAction(item.id)'>Buy</a>?
据我所知,您在存储数据的控制器的范围内。如果您有嵌套的ng重复,请查看$parent。
发布于 2017-03-06 20:15:39
如果希望在单击事件上将项的索引值传递到函数中,则只需传递它$index,而不是显式值。例如:
<div ng-repeat="item in model.Holdings track by $index">
<button class="btn btn-primary"
data-content="<a ng-click='onAction($index)'>Buy</a>...and more">
click me to show popup
</button>
</div>发布于 2017-03-06 21:42:48
https://stackoverflow.com/questions/42634530
复制相似问题