Routing with "id" parameter ends on white page

Asked

Viewed 233 times

0

When I routing with id parameter ends on white page. http://denertroquatte.com.br/app

My app starts appears the posts, so I click on the post it goes to the other page and "was to appear content" but it is all blank.

var app = angular.module('app', ['ngRoute', 'ngAnimate', 'ngSanitize']);

app.config(function($routeProvider){

    $routeProvider
    .when('/', {
        templateUrl: 'inicio.html'
    })  

    .when('/sobre',{
        templateUrl: 'sobre.html'

    })

    .when('/post/:postId',{
        templateUrl: 'post.html',
        controller: 'mostrarPost'
    })

});



//Aqui que se encontra o problema.
app.controller('mostrarPost', function($scope, $routeParams, $http){


$http.get('http://www.denertroquatte.com.br/database.php').success(function(data, status, headers, config){
            angular.forEach(data, function(item) {
              if (item.id_postagem == $routeParams.postId)

                $scope.i = $scope.items[$routeParams.id_postagem]

            });
        });

});

And here follows the List:

app.controller('listagemPost', function($scope, $http){

    $http.get('http://www.denertroquatte.com.br/database.php')
    .success(function(data, status, headers, config) {
            $scope.items = data;
     });

})

1 answer

1

Your code seems to be ok.

You could replicate the behavior on Jsfiddle? 'Cause that makes it easier for anyone who wants to help.

Can do the .get only of json which is returned from the bank.

EDIT

It seems that you were setting the parameter of $routeParams wrong way in the controller mostrarPost. The object $routeParams has as properties the same parameters defined in $routeProvider, that is, if you defined in your route that the parameter name is postId, then this will be the name by which this parameter will be accessible in $routeParams.


Your $scope.items receives an object with the property json_objs that has its posts, thus:

{"json_objs":[...]}

Soon, his $scope.i of mostrarPost should receive something like:

$scope.i = $scope.items.json_objs[$routeParams.postId]

You will also need to put the template references post.html according to the object returned by your $get, since the names are not according to the properties of the returned objects.

  • Need to be in Jsfiddle? Upload the application to the http://denertroquatte.com.br/app Thank you!

  • 1

    When asking for more information about the question/problem, use the comment area. Use the answer button only when answering a question.

  • Jean didn’t work out. He still has the same problem =/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.