gpt4 book ai didi

javascript - 如何从 Angular Controller 打开模态

转载 作者:行者123 更新时间:2023-11-30 07:15:08 25 4
gpt4 key购买 nike

我有一个 Angular Controller ,想在我的 View 中打开一个模式。

我的 HTML

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

<div class="modal-dialog">

<div class="modal-content">

<div class="modal-header">

<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>

<h4 class="modal-title" id="myModalLabel">Modal title</h4>

</div>

<div class="modal-body">

...

</div>

<div class="modal-footer">

<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>

<button type="button" class="btn btn-primary">Save changes</button>

</div>

</div>

</div>

</div>


Settings Controller

function SettingsController($scope,WalletManager,Storage){


$scope.pageClass = 'page-settings';


];



$scope.myModal = function () {

var modalInstance = $myModal.open({


});

如何从 Controller 打开?

最佳答案

根据 Soren 的建议,UI bootstrap是要走的路。下面是他们关于通过 AngularJS 打开模式的文档中的示例。

然后,一个 link使用下面的代码到他们的 Plunker。

<html>
<head>

<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.10/angular.js"></script>
<script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.11.0.js"></script>
<script src="example.js"></script>
<link href=
"//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel=
"stylesheet">

<title></title>
</head>

<body>
<div>
<script id="myModalContent.html" type="text/ng-template">
<div class="modal-header">
<h3 class="modal-title">I'm a modal!</h3>
</div>
<div class="modal-body">
<ul>
<li ng-repeat="item in items">
<a ng-click="selected.item = item">{{ item }}</a>
</li>
</ul>
Selected: <b>{{ selected.item }}</b>
</div>
<div class="modal-footer">
<button class="btn btn-primary" ng-click="ok()">OK</button>
<button class="btn btn-warning" ng-click="cancel()">Cancel</button>
</div>
</script> <button class="btn btn-default">Open me!</button>
<button class="btn btn-default">Large modal</button> <button class=
"btn btn-default">Small modal</button>

<div>
Selection from a modal: {{ selected }}
</div>
</div>
</body>
</html>

还有,javascript:

angular.module('plunker', ['ui.bootstrap']);
var ModalDemoCtrl = function ($scope, $modal, $log) {

$scope.items = ['item1', 'item2', 'item3'];

$scope.open = function (size) {

var modalInstance = $modal.open({
templateUrl: 'myModalContent.html',
controller: ModalInstanceCtrl,
size: size,
resolve: {
items: function () {
return $scope.items;
}
}
});

modalInstance.result.then(function (selectedItem) {
$scope.selected = selectedItem;
}, function () {
$log.info('Modal dismissed at: ' + new Date());
});
};
};

var ModalInstanceCtrl = function ($scope, $modalInstance, items) {

$scope.items = items;
$scope.selected = {
item: $scope.items[0]
};

$scope.ok = function () {
$modalInstance.close($scope.selected.item);
};

$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
};

关于javascript - 如何从 Angular Controller 打开模态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24815838/

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