instead of routeParams try: $route.current.params.variableName

Cheers,

Sam

On Wednesday, May 29, 2013 5:19:57 PM UTC+1, [email protected] wrote:
>
> I'm having the same issue as well. I can literally call 
> console.log($routeParams, $routeParams.parameter); and get different 
> results.
>
> angular.copy() returns an empty object, so that isn't any help, either.
>
> On Monday, February 11, 2013 11:22:24 AM UTC-5, Richard Brammer wrote:
>>
>> Hi Everyone,
>>
>> The weird thing is, that if you want to use any of the attributes within 
>> routeparams, you can't access their value. I changed the fiddle, so only 
>> the value of test should be given in the MyCtrl. 
>>
>> It know shows nothing which seems to be a problem for an application like 
>> this to run.
>>
>> Best regards,
>> Richard
>>
>> Am Montag, 27. August 2012 19:25:07 UTC+2 schrieb Pawel Kozlowski:
>>>
>>> Hi Roman! 
>>>
>>> Actually you can illustrate $route behavior with jsFiddle (or even 
>>> better - plunker), I was blogging about this few weeks back. 
>>>
>>> Anyway, this jsfiddle: 
>>> http://jsfiddle.net/pkozlowski_opensource/pt39h/1/ shows that you can 
>>> have access to $routeParams in both Main and Sub controllers. 
>>>
>>> The problems you were having in your example is that you were trying 
>>> to log things in a controller's constructor function. Those functions 
>>> are not run on each and every route change but only when a respective 
>>> scope is created / destroyed. 
>>>
>>> In your example the Main controller was called only once (at the 
>>> application's startup), before a route was matched so this is why it 
>>> was undefined. The sub-controller, on the other hand, is re-created on 
>>> each route match (and after a route is matched) so this is why it was 
>>> defined correctly. 
>>>
>>> Hope that the above explanations make sense but if not please feel 
>>> free to play with the attached fiddle and ask more questions. 
>>>
>>> Cheers, 
>>> Pawel 
>>>
>>> On Mon, Aug 27, 2012 at 6:03 PM, Roman Sachse 
>>> <[email protected]> wrote: 
>>> > Hi there, 
>>> > 
>>> > I have a problem with accessing the $routeParams service from a 
>>> controller. 
>>> > I can not get fiddle or plunker to work with routeParameters so I will 
>>> have 
>>> > to post the code here sorry. 
>>> > Request: .../#/view/hallo 
>>> > Html: 
>>> > <body ng-controller="MainCtrl"> 
>>> >   // loaded template 
>>> >   <div ng-view></div> 
>>> > 
>>> >   <script type="text/ng-template" id="templ"> </script> 
>>> > 
>>> > Angular: 
>>> > angular.module('myApp', []). 
>>> >   config(['$routeProvider', function($routeProvider) { 
>>> >     $routeProvider.when('/view/:test', {templateUrl: 'templ', 
>>> controller: 
>>> > SubCtrl}); 
>>> >   }]); 
>>> > 
>>> > function MainCtrl($routeParams) { 
>>> >     console.log($routeParam.test);  <=== undefined?!? 
>>> > } 
>>> > 
>>> > function SubCtrl($routeParams) { 
>>> >     console.log($routeParams.test); <== 'hallo', as expected 
>>> > } 
>>> > 
>>> > Is this the intended behavior? Why am I not able to access the route 
>>> Param 
>>> > from the main controller? 
>>> > 
>>> > Greeting, 
>>> > 
>>> > Ro 
>>> > 
>>> > -- 
>>> > You received this message because you are subscribed to the Google 
>>> Groups 
>>> > "AngularJS" group. 
>>> > To post to this group, send email to [email protected]. 
>>> > To unsubscribe from this group, send email to 
>>> > [email protected]. 
>>> > Visit this group at http://groups.google.com/group/angular?hl=en. 
>>> > 
>>> > 
>>>
>>

-- 
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