0

从尝试打开模式并应该执行 http 请求的下拉列表中更改值,并且正文将填充响应。但无法打开模态。任何帮助将不胜感激。

    <head>
        <title>Hello AngularJS</title>
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.13/angular.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.13.0/ui-bootstrap-tpls.min.js"></script>
    <link href="bootstrap.min.css" rel="stylesheet">
    </head>

    <body>
     <div ng-controller='NodeProvision'>   

<select ng-model="nodes" ng-change="nodeprovision(nodes)">
<option value="">please select</option>  
  <option value="1">One</option>
  <option value="2">Two</option>
</select>

 <script type="text/ng-template" id="myModalContent.html">
                                <div class="modal-header">
                                <h3 class="modal-title">Welcome to modal!!</h3>
                                </div>
                                <div class="modal-body">
                                <ul>
                                //<div ng-if="test">
                            <p>The response is {{items}} <span ng-bind="{{items}}"></span><i ng-hide="items"  class="icon icon-refresh icon-spin">loading.........</i></p>     
                            //</div>
                                </ul>                                
                               </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>
        <!-- <div ng-if="test">
            <p>The response is {{response}} <span ng-bind="{{response}}"></span><i ng-hide="response"  class="icon icon-refresh icon-spin">loading.........</i></p>     
        </div> -->
        </div>
    </body>

<script>
        //Initializing the app
        var app = angular.module('myApp',['ui.bootstrap']);

        //Defining the controller to perform the business logic
         app.controller('NodeProvision', ['$scope','$http','$modal', function($scope,$http,$modal) {  

            $scope.nodeprovision = function(node){

    $scope.animationsEnabled = true;

      $scope.open = function (size) {
        var modalInstance = $modal.open({
          animation: $scope.animationsEnabled,
          templateUrl: 'myModalContent.html',
          controller: 'ModalInstanceCtrl',
          size: size,
          resolve: {
            items: function () {
              $http.get('http://ac-00075763.devapollogrp.edu:8080/NodeProvision/provision/urn:apol:provider:acp/list?guid=5d4dc79e-f623-40f8-a14f-646c59c7b89a').
         success(function(data, status, headers, config) {
         $scope.items = data

         }).
         error(function(data, status, headers, config) {
           // log error
         });
            }
             }
            });  
             }; 
               }

         }]);



  app.controller('ModalInstanceCtrl', function ($scope, $modalInstance, items) {

  $scope.items = items;

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

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


    </script>
</html>
4

1 回答 1

2

Plunker 演示

这是您尝试做的一个相当简单的版本。我使用了一项服务(通常会使用 $http 请求获取记录)来解决问题,以保持整洁。

重要的是,您应该注意在解析对象中使用 return。没有这些,就没有任何信号表明一切都已完成,它可以允许 modal.open 完成它的事情! 这是一个很棒的教程,介绍如何将resolve与路由一起使用。$modal 服务中的 resolve 属性与 ngRoute 中的相同。

app.controller('ModalDemoCtrl', function ($scope, $modal, Data) {

  $scope.animationsEnabled = true;

  $scope.open=function(){
    var modalInstance=$modal.open({
      animation: true,
      templateUrl: 'myModalContent.html',
      controller: 'ModalInstanceCtrl',
      resolve: {
        loaddata: function(Data) {
                    return Data.get('allrecords');
                },
        selected: function () {
                    return $scope.model.id;
        }
      }
    });
  };

});

app.controller('ModalInstanceCtrl', function ($scope, $modalInstance, selected, loaddata) {

  $scope.allrecords = loaddata.records;
  $scope.selected = selected;

  $scope.cancel = function () {
    $modalInstance.dismiss('cancel');
  };
});
于 2015-06-04T19:24:09.080 回答