Skip to content

Commit

Permalink
readAllPosts() promise von Service in Controller aufrufbar gemacht
Browse files Browse the repository at this point in the history
  • Loading branch information
Minoletti Nathanael, P114 authored and Minoletti Nathanael, P114 committed Nov 4, 2019
1 parent 3554355 commit ab2406a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
27 changes: 9 additions & 18 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,28 @@
var app = angular.module("app", []);

app.controller("postListController", function($scope, PostService, $http) {
console.log("in postListController");
$scope.posts = PostService.readAllPosts();
console.log("posts-content: ", $scope.posts);
$http({
method: "GET",
url: "http://localhost:8080/postsafe",
headers: "Content-type: application/json"
}).then(function(value) {
$scope.ghesme = value.data;
console.log("ghesme-content: ", $scope.ghesme);
}, function(reason) {
$scope.ghesme = reason.data;
PostService.readAllPosts().then(function(value) {
$scope.posts = value;
console.log("posts-content: ", $scope.posts);//funktioniert nur innerhalb von funktion da abhängig von value
});
});

app.factory("PostService", function($http) {
var array = [];
return {
createPost: function(data) {

},
readAllPosts: function() {
console.log("in readAllPosts");
return $http({
method: "GET",
url: "http://localhost:8080/postsafe",
headers: "Content-type: application/json"
}).then(function succesful(response) {
array.push(response.data);
console.log("array: ", array);
return array;
}).then(function(response) {
return response.data;
}, function error(response) {
return response.data;
});
}

};
});
2 changes: 1 addition & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</head>
<body>
<div ng-controller="postListController">
<div ng-repeat="post in ghesme">
<div ng-repeat="post in posts">
<h1>{{post.title}}</h1>
<p>{{post.text}}</p>
</div>
Expand Down

0 comments on commit ab2406a

Please sign in to comment.