0

The console shows that the posts were retrieved successfully, the backend works fine without the angular compatibility.

and its supposed to retrieve post data.

angular.js:12701 XHR finished loading: GET "http://127.0.0.1:8000/auth/posts".

however it shows 5 empty divs like the following

enter image description here

main.js

$http.get('/auth/posts').then(function(data){
    $scope.myposts = data;

});

PostController

   public function getPosts()
    {

        $posts = Post::all();
        return json_encode($posts);
    }

Route

Route::get('auth/posts', 'HomeController@getPosts');

the html file

<div id="mypost" class="col-md-8 panel-default" ng-repeat="post in myposts">
    <div id="eli-style-heading" class="panel-heading"><% post.title %></div>
        <div class="panel-body panel">
            <figure>
                <p> <% post.body %></p>

            </figure>
        </div>
</div>
1
  • can you post the $scope.myposts values ? Commented Nov 14, 2017 at 7:50

1 Answer 1

2

You need to access the data property from the response, I think you need,

$http.get('/auth/posts').then(function(data){
    $scope.myposts = data.data;

});
Sign up to request clarification or add additional context in comments.

8 Comments

it worked thanks :), ill approve as soon as it let me
another thing, when i post it doest show automatically i have to refresh the page to see the new post. any recommondations ?
load it on the ng-init
just apply ng-init on the div tag where i have ng-repeat on ?
call the request to your api on ng-init with a function
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.