Routing with parameter "id" ends in white page

0

When I do routing with the id parameter ends in white page. link

My app starts the posts appear, so I click on the post it goes to the other page and "it was to appear the content" but everything goes 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's what's in the Listing:

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

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

})
    
asked by anonymous 06.11.2014 / 12:45

1 answer

1

Your code seems to be ok.

Could you replicate the behavior in JsFiddle ? Well, that makes it easier for those who want to help.

You can do .get only of json that is returned from the bank.

EDIT

It seems like you were setting the $routeParams parameter incorrectly in the mostrarPost driver. The $routeParams object has the same parameters defined in the $routeProvider , ie if you have 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 json_objs property that owns your posts, like this:

{"json_objs":[...]}

So, your $scope.i of mostrarPost should get something like:

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

You will also need to place the references of the post.html template according to the object returned by its $get , since the names do not conform to the properties of the returned objects.

    
06.11.2014 / 13:25