2017-04-15 74 views
0

现在我有春天服务,返回的ArrayList ..我做的阿勒特,以测试其在控制器返回的数组,它是作为一个JSON对象成功出现..但不显示任何以ng重复在HTML文件中为什么ng-repeat中没有显示任何内容?

HTML文件:

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

 
<head> 
 
<title>Student Page</title> 
 
<script>document.write('<base href="' + document.location + '" />');</script> 
 
    <link href="style.css" rel="stylesheet" /> 
 
    <script data-semver="1.2.28" src="https://code.angularjs.org/1.2.28/angular.js" data-require="[email protected]"></script> 
 
    <script src="https://code.angularjs.org/1.2.28/angular-route.js"></script> 
 
\t <script src="LogInController.js"></script> 
 
</head> 
 

 
<body> 
 
<div ng-app="phase2" > 
 
\t <div ng-controller="load" > 
 
\t \t <tr ng-repeat="x in sharedData"> 
 
\t \t \t <td> {{x.name}} </td> 
 
\t \t \t <td> => {{x.score}} </td> 
 
\t \t </tr> 
 
\t \t 
 
\t </div> 
 
</div> 
 
</body> 
 
</html>

LogInController.js:

var app = angular.module("phase2" , ['ngRoute']) 
 

 
app.config(["$routeProvider", "$locationProvider", function($routeProvider, $locationProvider){ 
 
    $routeProvider 
 
\t \t .when("http://localhost:8060/TheAngular_Project/LogInPage.html", { 
 
\t \t \t templateUrl: "LogInPage.html", 
 
\t \t \t controller: "LogIn" 
 
\t \t }) 
 
\t \t .when("http://localhost:8060/TheAngular_Project/StudentPage.html", { 
 
\t \t \t templateUrl: "StudentPage.html", 
 
\t \t \t controller: "load" 
 
\t \t }) 
 
\t \t .when("http://localhost:8060/TheAngular_Project/TeacherPage.html", { 
 
\t \t \t templateUrl: "TeacherPage.html", 
 
\t \t \t controller: "load" 
 
\t \t }) 
 
\t \t // .otherwise({ redirectTo: '/'}) 
 
\t \t ; 
 
}]); 
 

 
app.controller("LogIn" ,function ($scope , $http , srvShareData , $location) 
 
\t \t { 
 
\t \t \t $scope.dataToShare = []; 
 
\t \t \t $scope.save = function() { 
 
\t \t \t \t var email= document.getElementById("email").value; 
 
\t \t \t \t var Pass=document.getElementById("Pass").value; 
 
\t \t \t \t var Info ; 
 
\t \t \t \t $http.get('http://localhost:8090/LogIn/'+email+'/'+Pass) 
 
\t \t \t \t .then(function(response) 
 
\t \t \t \t \t { 
 
\t \t \t \t \t \t Info = JSON.stringify(response.data); 
 
\t \t \t \t \t \t $scope.dataToShare = Info ; 
 
\t \t \t \t \t \t srvShareData.addData($scope.dataToShare); 
 
\t \t \t \t \t \t //$scope.day=srvShareData.getData(); 
 
\t \t \t \t \t \t if ($scope.dataToShare.schema) 
 
\t \t \t \t \t \t \t { 
 
\t \t \t \t \t \t \t window.location.href="http://localhost:8060/TheAngular_Project/TeacherPage.html"; 
 
\t \t \t \t \t \t \t } 
 
\t \t \t \t \t \t else 
 
\t \t \t \t \t \t \t { 
 
\t \t \t \t \t \t \t window.location.href="http://localhost:8060/TheAngular_Project/StudentPage.html"; 
 
\t \t \t \t \t \t \t } 
 
\t \t \t \t \t }); 
 
\t \t \t \t } 
 
\t \t }); 
 

 
app.controller("load" , function($scope, srvShareData) 
 
\t { 
 
\t 
 
\t \t \t $scope.sharedData = srvShareData.getData(); 
 
\t \t \t alert($scope.sharedData) 
 
\t }); 
 

 

 
app.service('srvShareData', function($window) { 
 
    var KEY = 'App.SelectedValue'; 
 

 
    var addData = function(newObj) { 
 
    \t //$window.sessionStorage.clear(); 
 
     var mydata = $window.sessionStorage.getItem(KEY); 
 
     if (mydata) { 
 
      mydata = JSON.parse(mydata); 
 
     } else { 
 
      mydata = []; 
 
     } 
 
     mydata = newObj; 
 
     
 
     $window.sessionStorage.setItem(KEY, JSON.stringify(mydata)); 
 
    }; 
 

 
    var getData = function(){ 
 
     var mydata = $window.sessionStorage.getItem(KEY); 
 
     if (mydata) { 
 
      mydata = JSON.parse(mydata); 
 
     } 
 
     
 
     return mydata || []; 
 
    }; 
 

 
    return { 
 
     addData: addData, 
 
     getData: getData 
 
    }; 
 
});

+0

发表你有什么内部sharedData? – Sajeetharan

+0

@Pengyy其已存在 – Sajeetharan

+0

SharedData [{“name”:“Subtraction”,“scienceCategory”:null,“schema”:null,“score”:1500}] –

回答

2

在HTML中的一些变化,对我的工作的罚款(你也不必再使用ng-app):

HTML:

<body ng-controller="mainCtrl" class="container" style="padding-top:30px"> 
    <table> 
     <tr ng-repeat="x in sharedData"> 
     <td> {{x.name}} </td> 
     <td> => {{x.score}} </td> 
     </tr> 
    </table> 
    </body> 

脚本:

angular.module('app', []); 

angular.module('app').controller('mainCtrl', function($scope) { 
    $scope.sharedData = [{ 
    name: 'Subtraction', 
    score: 1500 
    }] 

}); 

这里是工作Plnkr:http://plnkr.co/edit/I1mfsgJfgsw1b92lJCkO?p=preview