【发布时间】:2016-08-19 18:25:53
【问题描述】:
我想在弹出窗口中显示一个可点击的表格,并在其中一行被点击时调用一个函数。我的 html 看起来像这样:
<a popover id="showDays"
type="button"
class="btn btn-success btn-xs pull-left"
data-toggle="popover"
data-placement="right"
data-html="true"
title="Popover title"
data-content=
'<table class="table table-condensed">
<tbody>
<tr ng-repeat="d in days" ng-click="show(111)">
<td ng-bind="d"></td>
<td ng-bind="x"></td>
</tr>
</tbody>
</table>'>
<i class="fa fa-clock-o fa-lg">Click me</i>
</a>
还有我的 script.js: var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.days = [
'Sunday',
'Monday',
];
$scope.show = function(x) {
console.log("show called with " + x);
$scope.x = x;
}
}).directive('popover', function($compile, $timeout){
return {
restrict: 'A',
link:function(scope, el, attrs){
var content = attrs.content;
var elm = angular.element('<div />');
elm.append(attrs.content);
$compile(elm)(scope);
$timeout(function() {
el.removeAttr('popover').attr('data-content',elm.html());
el.popover();
});
}
}
});
代码是从这个question 复制的,答案本身可以正常工作,但是我的show 函数没有被调用。知道为什么吗?
【问题讨论】:
-
标记为“为什么这段代码不起作用”
-
@AlexandreMartin,这是什么意思?我应该怎么问这个问题?
-
你没有使用
ui-bootstrap的popover元素 -
@PankajParkar,不,我只想使用引导程序,它应该能够做到这一点。
标签: javascript angularjs twitter-bootstrap