What's happening is that the XHR call is being made before you give
`article_id` a value, which should be expected. Do you want to make the
call every time the `$routeChangeSuccess` event is broadcasted? If so, try
moving your `$http` call inside your event callback and see if that works.


On Tue, Apr 8, 2014 at 3:00 PM, Philipp Blum <[email protected]>wrote:

> Hello,
>
> i have a big problem. I want to use a scope variable in a rest call but i
> dont know how. In the html i can use the article_id but not in a
> subfunction. How i can declare the variable as global or how i can use the
> variable in my second function?
>
> articlepage_module.controller('ArticleCtrl',
>     function ($scope, $http, $routeParams, $route)
>     {
>         var article_id;
>         $scope.$on('$routeChangeSuccess', function(Event, routeData){
>
>             $scope.article_id = routeData.params.article_id;
>             article_id = routeData.params.article_id;
>             //output 1 -->current article page
>             console.log(routeData.params.article_id);
>         });
>
>         //output undefined
>         console.log(article_id);
>         $http({method: 'GET', url: 'artikel/index.php', params:
> {'article_id': article_id}}).success(function(data)
>         {
>             $scope.article_details = data; // response data
>         });
>     }
> );
>
> --
> You received this message because you are subscribed to the Google Groups
> "AngularJS" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/angular.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
*James Brewer*
*http://www.brwr.org/ <http://www.brwr.org/>*

*Software Engineer @ RealScout | What is RealScout?
<http://vimeo.com/72791570>*

*Twitter* *twitter.com/jamesbrwr <http://twitter.com/jamesbrwr>*
*GitHub* *github.com/brwr* <http://github.com/brwr>
*StackOverflow** stackoverflow.com/users/2052923/james-brewer
<http://stackoverflow.com/users/2052923/james-brewer>*
*LinkedIn* *linkedin.com/in/jamesbrwr <http://linkedin.com/in/jamesbrwr>*

→ *M**y favorite RealScout search is Modern & High-Tech Homes in Atherton
<https://kendeleon.realscout.com/categories/modern-high-tech?utf8=%E2%9C%93&loc=Atherton>*

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to