2017-05-31 14 views
0

使用php從數據庫獲取數據。數據沒問題。在NgModel框中不顯示對接數據。我已經在ngdialog函數中傳遞了scope參數。請幫助我。如何使用http方法獲取ng對話框中的數據angularjs?

var adminapp = angular.module("uibootstrap", ["ngRoute", 'ngDialog']); 
 
adminapp.controller("homedata", function($scope, $rootScope, $http, $httpParamSerializerJQLike, ngDialog, $timeout) { 
 

 
    $rootScope.theme = 'ngdialog-theme-default'; 
 

 
    $scope.openDefault = function() { 
 
    ngDialog.open({ 
 
     template: 'firstDialogId', 
 
     className: 'ngdialog-theme-default', 
 
     scope: $scope 
 
    }) 
 
    }; 
 
    // get user 
 
    $http.get('http://localhost/database/get-user.php').success(function(response) { 
 
    $scope.users = response; 
 
    }); 
 

 
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<li ng-repeat="item in users"> 
 
    <a href="javascript:void(0);" ng-click="openDefault()"> 
 
    <div class="img"><img alt="" src="admin/images/user-img2.jpg"> <span class="status-red"></span></div> 
 
    <div class="msginfo"> 
 
     {{item.user_name}} <br> <span>{{item.user_status}}</span> 
 
    </div> 
 
    </a> 
 
    <script type="text/ng-template" id="firstDialogId"> 
 
    <div class="ngdialog-message"> 
 
     <div class="data"> 
 
     <div class="img"> 
 
      <img alt="" src="http://localhost/rockeditor/admin/images/img-user.png"> <a class="editbtn" href="#"><i class="fa fa-edit"></i></a> 
 
     </div> 
 
     <div class="name">{{item.user_name}}</div> 
 
     <span class="editor">{{item.user_status}}</span> 
 
     <span class="email">{{item.user_email}}</span> 
 
     <input class="btn-green" type="submit" value="Save"> 
 
     </div> 
 
    </div> 
 
    </script> 
 
</li>

+0

對話框是否打開? –

+0

是打開罰款。但是空的。價值顯示在模型框外。 –

回答

0

變量item是不是在你的模板firstDialogId可用的,其實它不是<li></li>

0

子節點。您忘了在HTML controller

  • <li>元素
  • item上使用ng-controller="homedata"是不是在script標籤訪問
  • $scope.users$http調用之後成功響應返回

看到這裏

<!DOCTYPE html> 
<html> 

<head> 
    <link rel="stylesheet" href="ngDialog.css" /> 
    <link rel="stylesheet" href="ngDialog-theme-default.css" /> 
    <script data-require="[email protected]*" data-semver="1.3.0" src="//code.angularjs.org/1.3.0/angular.js"></script> 
    <script src="ngDialog.js"></script> 

    <link rel="stylesheet" href="style.css" /> 
    <script src="script.js"></script> 

</head> 

<body ng-app="MyApp" ng-controller="homedata"> 


    <button ng-click="clickme()">Hello World</button> 
    <script type="text/ng-template" id="firstDialogId"> 
    <div ng-repeat="user in users"> 
     <div>Current user:</div> 
     <div>{{user.name}}</div> 
    </div> 
    </script> 
</body> 

</html> 

的script.js

// Code goes here 
angular.module("MyApp", ['ngDialog']) 
    .controller("homedata", homedata) 

function Main($scope, ngDialog) { 
    $scope.users = [ 
     {name: 'abc'}, 
     {name: 'xyz'} 
    ]; 
    $scope.clickme = function() { 
    ngDialog.open({ 
     template: 'firstDialogId', 
     className: 'ngdialog-theme-default', 
     scope: $scope 
    }); 

    }; 
} 

但按您的控制器,有一個$http呼叫,直到它回答您不必在$scope.users任何數據。所以,請確保它和你的對話框中只有$http獲得成功響應後才能獲得數據。

相關問題