【发布时间】:2017-07-25 14:53:05
【问题描述】:
我是 Angular 的新手。我创建了一个带有模板 (panel.html) 和控制器 (allPanelsRetrieved) 的组件。当单击模板中定义的特定按钮时,将调用控制器中指定的 showDetails() 函数。此函数触发由模板 (panel-list.details-template.html) 和控制器指定的模式对话框的打开,它们都在 allPanelsRetrieved 控制器中定义。问题是显示了模态对话框,但控制器不起作用(单击“确定”按钮没有任何作用)。问题可能出在哪里?提前致谢
angular.
module('panelList')
.component('panelList', {
templateUrl: '/panel-list/panel.html',
controller: ['Panel', 'NgTableParams','$scope', '$location', '$uibModal',
function PanelListController(Panel, NgTableParams, $scope, $location, $uibModal) {
this.allPanelsRetrieved = (index, before) => {
//..hidden code here
}
this.showDetails = function () {
$uibModal.open({
templateUrl: '/panel-list/panel-list.details-template.html',
controller: function ($uibModalInstance) {
let $ctrl = this;
$ctrl.ok = function () {
$uibModalInstance.close();
};
},
}).result.then(
function (success) {
alert(success);
},
function (error) {
alert(error);
}
);
};
}]
});
这里是模板 panel-list.details-template.html:
<div>
<script type="text/ng-template" id="/panel-list/panel-list.details-template.html">
<div class="modal-header">
<h3 class="modal-title">Modal title</h3>
</div>
<div class="modal-body">
Modal content
</div>
<div class="modal-footer">
<button class="btn btn-primary" ng-click="$ctrl.ok()">Close</button>
</div>
</script>
【问题讨论】:
-
能否添加
panel-list.details-template.html的代码? -
我刚刚加了
标签: javascript angularjs