var modalInstance = $modal.open({
templateUrl: '/static/js/controllers/dashboard/search.html',controller: 'searchCtrl',size: 'lg',resolve: {
formSize: function () {
return {
width: '480px',height: 'auto'
}
},mydisplayed: function () {
return $scope.mydisplayed; //返回值给模态框
}
},scope: scope
});
modalInstance.result.then(function (res) {
$scope.mydisplayed = res;
}); //获取模态框的返回值 在模态框的控制器中定义模态框关闭时,返回给主页面的值:
$modalInstance.close($scope.result); //$scope.result 模态框控制器返回的值。
下面是具体的详情,摘自网络(https://my.oschina.net/codingBingo/blog/715869):
html页面:
然后在引入自己写的一个控制器文件app.js
重点就是接下的几点了
关于modal控制器中的close与dismiss这两个函数,我在网上找了一个详细的说明
意思就是说close呢是用于关闭模态框的方法,返回的是一个result--结果
dismiss也是用于关闭模态框的方法,但返回的是一个reason--理由
这么说应该很好理解了吧,
再说的详细一点就是,看代码
<div ng-controller="ModalDemoCtrl"> <script type="text/ng-template" id="myModalContent.html"> <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 href="#" ng-click="$event.preventDefault(); selected.item = item">{{ item }}</a> </li> </ul> Selected: <b>{{ selected.item }}</b> </div> <div class="modal-footer"> <button class="btn btn-primary" type="button" ng-click="ok()">OK</button> <button class="btn btn-warning" type="button" ng-click="cancel()">Cancel</button> </div> </script> <button type="button" class="btn btn-default" ng-click="open()">Open me!</button> <button type="button" class="btn btn-default" ng-click="open('lg')">Large modal</button> <button type="button" class="btn btn-default" ng-click="open('sm')">Small modal</button> <button type="button" class="btn btn-default" ng-click="toggleAnimation()">Toggle Animation ({{ animationsEnabled }})</button> <div ng-show="selected">Selection from a modal: {{ selected }}</div> </div><script src="app.js"></script>angular.module('ui.bootstrap.demo',['ngAnimate','ui.bootstrap']);
angular.module('ui.bootstrap.demo').controller('ModalDemoCtrl',function ($scope,$uibModal,$log) {
$scope.items = ['item1','item2','item3'];
$scope.animationsEnabled = true;
$scope.open = function (size) {
var modalInstance = $uibModal.open({
animation: $scope.animationsEnabled,
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());
});
};
$scope.toggleAnimation = function () {
$scope.animationsEnabled = !$scope.animationsEnabled;
};
});
angular.module('ui.bootstrap.demo').controller('ModalInstanceCtrl',$uibModalInstance,items) {
$scope.items = items;
$scope.selected = {
item: $scope.items[0]
};
$scope.ok = function () {
$uibModalInstance.close($scope.selected.item);
};
$scope.cancel = function () {
$uibModalInstance.dismiss('cancel');
};
});modalInstance.result.then(function (selectedItem) {
});
modalInstance.reason.then(function (selecteItem) {
}); (编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|