角度不显示$scope数据,ng 重复传入控制器.也没有错误


Angular not displaying $scope data with ng repeat passed in controller. No errors too

在这个项目中,我正在对ionic的点击列表项执行查询。我正在从 php json_encode 获取数据。数据显示在"响应"下的"网络"选项卡中。另外,我还添加了$scope.doctorList = {};之后写了这一行$scope.doctorList = 来自成功函数的响应。数据也显示在console.log($scope.doctorList)中。

现在,当我尝试以角度显示此数据时,它不会显示任何内容。我已将其包含在ng-repeat中,因为:ng-repeat ="医生列表中的医生"

语法似乎是正确的,因为同样的事情适用于另一个控制器,但在这里,我无法检索数据。页面变为空白,控制台/网络选项卡中没有错误。

我正在为两个 html 文件使用一个控制器。请帮忙

这是路由文件

angular.module('app.routes', []).config(function ($stateProvider, $urlRouterProvider, $ionicConfigProvider) {
    $stateProvider.state('homeselect', {
        url: '/home-select',
        templateUrl: 'templates/homeselect.html',
        controller: 'homeCtrl'
    });
    $stateProvider.state('home', {
        url: '/home',
        templateUrl: 'templates/home.html',
        controller: 'homeCtrl'
    });
});

这是控制器

angular.module('app.controllers', []).controller('homeCtrl', function ($scope, $http, $ionicSideMenuDelegate, myServices, $window) {
    $ionicSideMenuDelegate.toggleLeft();
    $scope.loadDoc = function (type) {
        $http({
            url: "http://localhost/drmedic/retrieve_details_type.php",
            method: "POST",
            data: {
                data: type
            }
        }).success(function (response) {
            $scope.doctorList = {};
            $scope.doctorList = response;
            $window.location.href = '#/home-select';
        });
    };
    $http({method: 'GET', url: 'http://localhost/drmedic/retrieve_details.php'}).success(function (data) {
        $scope.contents = {};
        $scope.contents = data;
    });
});

这是 ng-repeat 的 html 文件代码

<ion-list ng-repeat="doctors in doctorList">
  <ion-item>
  <center>
    {{doctors.name}}<br>
    {{doctors.fees}}
  </center>
  </ion-item>
</ion-list>

您可以使用服务。打开一个名为 service.js.之后,这将注入到app.js。我修改了代码如下:

服务.js:

 angular.module('app.services', [])
    .factory("AppService", function ($http) {
        var AppService= {};
        AppService.GetDetails = function (data) {
            return  $http({
            url: "http://localhost/drmedic/retrieve_details_type.php",
            method: "POST",
            data: {
                data: data
            }
            });
        return AppService;
        }

控制器.js:

.controller('homeCtrl',function($scope,$http,$ionicSideMenuDelegate,myServices,$window,AppService) {
        $ionicSideMenuDelegate.toggleLeft();
        $scope.loadDoc = function(type){
       AppService.GetDetails({type:type}).success(function (response) {
              $scope.doctorList = {}; 
              $scope.doctorList = response;
              $window.location.href = '#/home-select';
        })
        .error(function (err) {
              console.log(err);
        });
   }
});

ng-repeat遍历一系列项目,创建自己的范围并将其呈现在UI上。当我说集合时,它应该是一个数组。https://docs.angularjs.org/api/ng/directive/ngRepeat

请检查医生列表的数据类型,我相信它是一个数组。

$scope.doctorList = []; 

我希望这应该解决问题,如果没有,请分享代码,我会深入研究它。