angular js显示获取的数据到ngDialog

时间:2018-06-13 10:16:07

标签: angularjs ng-dialog

我想从服务器获取数据并将其显示到ngDialog对话框

我正在尝试以下代码



var myApp = angular.module('myApp', ['ui.router', 'ngDialog']);
myApp.controller('test', function($scope, $http, ngDialog) {
  $scope.plist = [];
  $scope.pno = 1;
  $scope.likeDetails = function(item) {
    var data = 'id=' + item.id + "&userid=" + $scope.userid +
      "&pno=" + $scope.ppno;
    $http({
      method: 'POST',
      url: "show-liked-users",
      data: data,
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
      }
    }).then(function successCallback(rs, status, headers, config) {
      console.log(rs);

      for (var i = 0; i < rs.data.plist.length; i++) {
        $scope.plist.push(rs.data.plist[i]);
      }

    }, function errorCallback(data, status, header, config) {
      alert("Opps unable to connect to server");
    });
    ngDialog.open({
      template: 'liked-user-page',
      className: 'ngdialog-theme-plain',
      scope: $scope,
      data: $scope.plist
    });
  };
});
&#13;
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.9/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/1.0.18/ui-router-angularjs.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ng-dialog/1.4.0/js/ngDialog.js"></script>

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ng-dialog/1.4.0/css/ngDialog.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ng-dialog/1.4.0/css/ngDialog-theme-default.css" />

<html>

<body ng-app="myApp">
  <div ng-controller="test">
    <div class="like-count" ng-click="likeDetails(s)">
      5
    </div>
  </div>
</body>

</html>
&#13;
&#13;
&#13;

like-user-page url包含一个页面

<div ng-repeat="i in plist">
{{i.fname}} {{i.lname}}
</div>

这里我称之为“show-like-details&#39;获取返回用户的id,fname,lname的json数据。 我想在ngDoalog框中显示这些数据 在打开ngdialog它是文本like-user-page

我想迭代plist insode&like-user-page&#39;(这是代表服务器中的页面的url)数据并将其显示给ngdialog。 以及如何在ngDialog中调用url

1 个答案:

答案 0 :(得分:0)

你应该在$ http电话的成功回调中打开你的对话。

var myApp = angular.module('myApp', ['ui.router', 'ngDialog']);
myApp.controller('test', function($scope, $http, ngDialog) {
  $scope.plist = [];
  $scope.pno = 1;
  $scope.likeDetails = function(item) {
    var data = 'id=' + item.id + "&userid=" + $scope.userid +
      "&pno=" + $scope.ppno;
    $http({
      method: 'POST',
      url: "show-liked-users",
      data: data,
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
      }
    }).then(function successCallback(rs, status, headers, config) {
      console.log(rs);

      for (var i = 0; i < rs.data.plist.length; i++) {
        $scope.plist.push(rs.data.plist[i]);
      }
      ngDialog.open({
        template: 'liked-user-page',
        className: 'ngdialog-theme-plain',
        scope: $scope,
        data: $scope.plist
      });
    }, function errorCallback(data, status, header, config) {
      alert("Opps unable to connect to server");
    });

  };
});