我对angularjs有问题。打开弹出窗口并在弹出窗口上动态添加一个按钮后,我不知道如何触发一个按钮事件。我几乎尝试了"一切"。
这是一个示例:https://plnkr.co/edit/qfndttje2onfhzt65tbq?p=preview
确定您的代码可以有所改进,但这应该是可靠的解决方案:https://plnkr.co/edit/uiosyhbjvztw33yr6h3z?p=preview
javaScript:
app.controller('ModalInstanceCtrl', function ($uibModalInstance,$compile) {
var $ctrl = this;
$ctrl.buttonArray = [];
$ctrl.cancel2 = function () {
$uibModalInstance.dismiss('cancel');
};
$ctrl.add2 = function(){
$ctrl.buttonArray.push('message' + $ctrl.buttonArray.length)
};
$ctrl.message = function () {
alert('Message');
};
});
html:
<div ng-app="app" ng-controller="postoviCtrl as $ctrl">
<script type="text/ng-template" id="modalOdabraniPost.html">
<div class="modal-body">
<p>Header</p>
<hr/>
<button class="btn btn-sm" type="button" ng-click="$ctrl.add2()">Add</button>
<div id="content">
<button ng-repeat="btn in $ctrl.buttonArray" class="btn btn-primary btn-sm" type="button" ng-click="$ctrl.message()">{{btn}}</button>'
</div>
</div>
<div class="modal-footer">
<button class="btn btn btn-primary" type="button" ng-click="$ctrl.cancel2()">Close</button>
</div>
</script>
<a href="" class="label label-danger" ng-click="$ctrl.open2()">Open</a>
</div>