我想打印来自服务器的整个结果 - AngularJs

时间:2018-02-16 12:02:57

标签: angularjs

我是angularJs的新手。我正在做一个带弹簧靴和angularJs的大学项目。

我想打印来自服务器的所有结果。

这是我的代码。

app.js

'use strict';

    var App = angular.module('myApp',[]);

HomeController.js

 'use strict';


App.controller('HomeController', ['$scope', 'HomeService', function($scope, HomeService) {


$scope.getDeviceList = function () {
        HomeService.getDeviceList()
          .then (function success(response){ 
              $scope.details = responce.data;
              $scope.errorMessage = '';
          },
          function error(response){
              $scope.errorMessage = 'Error occured!!!';
              $scope.message = response.data.message;
        });
    }

}]);

HomeService.js

'use strict';

App.service('HomeService', ['$http', '$q', function($http, $q){


var REST_SERVICE_URI = '/customer';




this.getDeviceList = function getDeviceList(){
    return $http.get(REST_SERVICE_URI + '/get_device_list')

}

}]);

home.html的

 <!DOCTYPE html>
<html ng-app="myApp">

    <head>
        <title>Welcome to Ncheck Surveilance</title>

        <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.0/angular.js"></script>
        <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.0/angular-route.js"></script>
        <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/1.0.3/angular-ui-router.js"></script>
        <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.0/angular-resource.js"></script>


        <script type="text/javascript" src="../js/app.js"></script>
        <script type="text/javascript" src="../controller/RegistrationController.js"></script>
        <script type="text/javascript" src="../controller/HomeController.js"></script>
        <script type="text/javascript" src="../service/RegistrationService.js"></script>
        <script type="text/javascript" src="../service/HomeService.js"></script>

      </head>

</html>   
<body ng-controller="HomeController">

    Logged in user: <b th:inline="text"> [[${#httpServletRequest.remoteUser}]] </b>
    <br>
    <span class="panel-title">Registered Devices</span>
     <span>
            <button id="button" name="button" class="btn btn-primary"   ng-click="getDeviceList()" >Show</button>
                 {{details}}
            {{error}}
    </span>
   <div>
        Hello : <b th:inline="text">  </b>
        <form th:action="@{/logout}" method="POST">
            <input type="submit" value="Logout"/>
       </form>
   </div> <br/>  
</body>

我的问题是当我点击“显示”按钮时,我在网络浏览器控制台中收到错误(可能是未处理的拒绝:{})。

0 个答案:

没有答案