如何在url中显示模态内的信息?

Fru*_*tis 5 javascript modal-dialog angularjs

我对js总体上很新,所以请耐心等待我.

我需要做一个在主题中说明的简单任务.我已经做了一些研究,并试图使用ui.router,但因为我不是很好编码出错了.

我希望来自url的这些信息将显示在模式对话框http://prntscr.com/ashi5e中

所以这是代码:

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

    $scope.open = function () {

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


    };
};

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

    $scope.cancel = function () {
        $modalInstance.dismiss('cancel');
    };
};
Run Code Online (Sandbox Code Playgroud)
<!doctype html>
<html ng-app="plunker">
<head>
 <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.js"></script>
 <script src="http://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.6.0.js"></script>
 <script src="js/example.js"></script>
 <link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css" rel="stylesheet">
</head>
<body>

<div ng-controller="ModalDemoCtrl">
 <script type="text/ng-template" id="myModalContent.html">
  <div class="modal-header">
   <h3>Log</h3>
  </div>
  <div class="modal-body">

   Content
  </div>
  <div class="modal-footer">
   <button class="btn btn-warning" ng-click="cancel()">Close</button>
  </div>
 </script>

 <button class="btn" ng-click="open()">Log</button>

</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

tro*_*llr 2

您需要获取数据(例如通过服务)并将其放入 $scope.items 中。在您的模式中执行相同的操作:获取项目并将其绑定到您的范围。就这样

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

    /* Get data here with a service or smth */
    $scope.items = '';

    $scope.open = function () {
       $http.get("YOUR_URL")
         .then(function(response) {
            $scope.items = response.data
            var modalInstance = $modal.open({
                  templateUrl: 'myModalContent.html',
                  controller: 'ModalInstanceCtrl',
                  resolve: {
                     items: function () {
                        return $scope.items;
                  }
                }
             });
         });
    };
};

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

    $scope.cancel = function () {
        $modalInstance.dismiss('cancel');
    };
};
Run Code Online (Sandbox Code Playgroud)
<!doctype html>
<html ng-app="plunker">
<head>
 <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.js"></script>
 <script src="http://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.6.0.js"></script>
 <script src="js/example.js"></script>
 <link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css" rel="stylesheet">
</head>
<body>

<div ng-controller="ModalDemoCtrl">
 <script type="text/ng-template" id="myModalContent.html">
  <div class="modal-header">
   <h3>Log</h3>
  </div>
  <div class="modal-body">
    {{items}}
  </div>
  <div class="modal-footer">
   <button class="btn btn-warning" ng-click="cancel()">Close</button>
  </div>
 </script>

 <button class="btn" ng-click="open()">Log</button>

</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)