gpt4 book ai didi

angularjs - Angular Modal - 关闭/关闭模式

转载 作者:行者123 更新时间:2023-12-03 17:40:44 25 4
gpt4 key购买 nike

我是 Angular 的新手,正在尝试实现模态。关闭/关闭模式时出现问题 - 当我单击取消按钮时,没有任何 react 。
这是 Controller 代码:

angular.module('navApp')
// Passing the $modal to controller as dependency
.controller('HomeCtrl', ['$scope', '$uibModal', function ($scope, $uibModal) {
$scope.title = "Hello, Angm-Generator!";
$scope.open = function () {
var modalInstance = $uibModal.open({
templateUrl: 'myModalContent.html',
controller: 'ModalCtrl'
});
};
}])

.controller('ModalCtrl', function ($scope, $uibModalInstance) {
// Added some content to Modal using $scope
$scope.content = "ModalCtrl, Yeah!"
// Add cancel button
$scope.cancel = function () {
$uibModalInstance.dismiss('cancel');
};
})

这是实际模态的模板 View
<!-- Modal Script -->
<script type="text/ng-template" id="myModalContent.html">
<div class="modal-header">
<button type="button" class="close" datadismiss="modal" aria-hidden="true">&times;</button>
<h3 class="modal-title">Hello from Modal!</h3>
</div>
<div class="modal-body">
Modal Content from: <b>{{ content }}</b>
</div>
<div class="modal-footer">
<button class="btn btn-danger" ngclick="cancel()">Cancel</button>
</div>
</script>

即使单击模态框右上角的十字也不会关闭模态框。有任何想法吗?谢谢:)

最佳答案

应该不是 ng-click="cancel()"而不是 ngclick ?

另外我不认为范围绑定(bind)到 Controller ,我没有测试过这个,但我相信你需要更多的选择:

var modalInstance = $uibModal.open({
templateUrl: 'myModalContent.html',
controller: 'ModalCtrl',
controllerAs: '$mCtrl',
bindToController: true
});

然后只需更新您的模板:
ng-click="$mCtrl.cancel()"

关于angularjs - Angular Modal - 关闭/关闭模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37288794/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com