【问题标题】:angular js showing fetched data to ngDialog角度 js 向 ngDialog 显示获取的数据
【发布时间】:2018-06-13 10:16:06
【问题描述】:

我想从服务器获取数据并显示到 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
    });
  };
});
<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>

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

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

在这里我调用“show-like-details”来获取返回用户的 id、fname、lname 的 json 数据。 我想在 ngDoalog 框中显示这些数据 在打开的 ngdialog 上,它正在显示喜欢的用户页面

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

【问题讨论】:

  • 尝试绑定到 'i' 对象:&lt;div ng-repeat="i in plist"&gt; {{i.fname}} {{i.lname}} &lt;/div&gt;
  • 更正了问题不起作用
  • @xrcwrn 你有要更新的插件吗?
  • 不,我会创建

标签: angularjs ng-dialog


【解决方案1】:

您应该在 $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");
    });

  };
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多