简体   繁体   English

如何在angularjs-ui bootstrap中使用模态弹出窗口

[英]how to use modal pop up in angularjs-ui bootstrap

I'm using angularjs. 我正在使用angularjs。 What i want to do is when user click button , angularjs will checking item id in database. 我想要做的是当用户点击按钮时,angularjs将检查数据库中的项目ID。 If item id exist in database, #modal will be showed instead of alert like this question. 如果数据库中存在项目ID,则会显示#modal而不是像此问题的警告。 Is it possible to do this with angularjs? 是否可以使用angularjs执行此操作? If possible how.. 如果可能的话......

HTML HTML

    <div id="container" ng-app='two_way' ng-controller="aa" >
<div align="center">
 <h1 align="center">  Nutrition Scheduling List </h1>
        <button ng-click="loadsched()" >LOAD SCHEDULE</button>
</div>
<span ng-hide="load==null">
<table border='1' bgcolor="CCFFFF" align="center">
<tr ><td><b>Item Name</b></td><td><b>Scheduled Time</b></td><td><b>Run Time</b></td><td><b>Create Time</b></td><td><b>Status</b></td><td><b>Response</b></td></tr>
 <tr ng-repeat="data in load | orderBy: 'searchitem'">
    <td>
         {{data.searchitem}}
        </td>
    <td>
         {{data.Scheduledtime}}
        </td>
    <td>
         {{data.runt}}
        </td>
    <td>
         {{data.CurrentTime}}
        </td>
    <td>
         {{data.STATUS}}
        </td>
    <td>
<input type="button" class="btn btn-lg btn-primary" value="RESPONSE" onclick="window.open('http://localhost:3000/search/{{data._id}}','popUpWindow','height=500,width=400,left=100,top=100,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no, status=yes');">
        </td>
</tr>
</table>
</span>
    <script src="more.js"></script>
    </div>

Controller more.js 控制器more.js

var app=angular.module('two_way', ['ui.bootstrap']);
app.controller('aa',function($scope,$http){

$scope.loadsched=function(){

  $http.post("http://localhost:3000/a").success(function(data){    
//console.log(data);

    $scope.load=angular.fromJson(data);



  }).error(function(){alert("Error");});
}


});

Very simple :- 很简单 :-

1) Apply $modal to your main controller. 1)将$ modal应用于主控制器。

2) Use $modal.open() to open modal anywhere and it will return a promise. 2)使用$modal.open()在任何地方打开模态,它将返回一个promise。

 $modal.open({
      templateUrl: 'myModalContent.html',
      controller: 'ModalInstanceCtrl',
      size: size
);

Here template is file or Id of your modal template. 这里模板是模态模板的文件或Id。 size:sm,lg Controller it is the controller of your modal. size:sm,lg控制器它是你的模态的控制器。 For example:- 例如:-

angular.module('ui.bootstrap.demo').controller('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');
  };
});

$modalInstance service is used to close and return the promise from modal. $ modalInstance服务用于关闭并从模态返回promise。

$modalInstance.close($scope.selected.item); close the modal and return data to controller. 关闭模态并将数据返回给控制器。

$modalInstance.dismiss('cancel'); it is simply dismiss the controller. 它只是解雇了控制器。

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

Here modalInstance.result is used to get data from modal controller to your main controller. 这里modalInstance.result用于从模态控制器获取数据到主控制器。

Official Plunker 官方的Plunker

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM