the ng-repeat model doesn't update after a user clicks submit, it will only show on refresh, i reviewed a similar problem, but i couldn't connect the dots. A user recommended i do a ng-init, but i don't think im doing it right.
with ng-init it shows no data, without ng-init and removing the angular function it shows posts but doesn't update the model after click.
note:the angular brackets are replaced because laravel blade doesn't like it
html
<div id="mypost" class="col-md-8 panel-default" ng-init="getPosts()" 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>
Main.js
// this doens't show posts when i use ng-init
$scope.getPosts = function(){
$http.get('/auth/posts').then(function(data){
$scope.myposts = data.data;
});
};
// this shows posts without ng-init but doesn't update when a user adds data
$http.get('/auth/posts').then(function(data){
$scope.myposts = data.data;
});
Updated Again
network error
PostController.php
public function storePost(Request $request)
{
$data = request()->validate([
'title' => 'required|max:120',
'body' => 'required|max:1000'
]);
$data['user_id'] = auth()->user()->id;
$post = Post::create($data);
// return redirect('/home')->withMessage('A new post was created.');
return Response::json(array('success' => true));
}