Using stateparams is not returning json to display in detail

Asked

Viewed 42 times

1

Guys, I have the following problem:

I have a json file, and I’m making his call like this:

$http.get("../templates/teste.json").success(function (response) {

    $scope.x = response;

});

On my route, it’s like this:

.state('app.detalhe', {
    url: '/produtos/:ProdutoId',
    views: {
        'menuContent': {
            templateUrl: 'templates/detalhe.html',
            controller: 'ProdutosCtrl'
        }
    }
})

On my controller, it’s like this:

$scope.produtoSingle = function () {

     x[$stateParams.produtoId]; }

}

The url is sending correct:

And he just doesn’t give me back any details, someone would tell me what’s going on?

  • Fixing: x[$stateParams.productId]; }

  • productId instead of fruitId? You can edit your post, I’ll fix it for you. How’s your JSON file?

  • Yes, I will produce instead of fruitId. My json is like this:

  • [ { "title":"Title", "Subtitle":"Lorem ipsum", }, { "title":"Title 2", "Subtitle":"Lorem ipsum 2", }, { "title":"Title 3", "Subtitle":"Lorem ipsum 3", }&#Xa";]

  • you defined the $stateParams in the controller? your $stateParams.produtoId is syntax different from the parameter on the router, which is ProdutoId. Anything if unsolved, update with your full controller (or at least startup) to check.

  • 1

    that key after array x[ ... ]; is left over... besides the "x" is this.x

Show 1 more comment

1 answer

0

See my answer in: /a/100066/8386

Try:

$http.get("../templates/teste.json").success(function (response) {

    $scope.x = response;
    if (!$scope.$$phase) $scope.$apply();
});

Browser other questions tagged

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