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
};
});
發表你有什麼內部sharedData? – Sajeetharan
@Pengyy其已存在 – Sajeetharan
SharedData [{「name」:「Subtraction」,「scienceCategory」:null,「schema」:null,「score」:1500}] –