I will try service. Thank you All!
On Friday, February 28, 2014 3:50:21 AM UTC-7, Zhenghao Huang wrote:
>
> Agreed, Service is better practice.
>
> On Friday, 28 February 2014 16:15:41 UTC+8, Luke Kende wrote:
>>
>> If you are using $rootScope, which I personally think a service is the 
>> better practice, you will need to use ng-click and point it to a function 
>> that references the clicked object:
>>
>> <li ng-repeat="object in objects">
>>   <a ng-click="viewObject(object)">View</a>
>> </li>
>>
>> function TheCtrl($location){
>>   $scope.objects = [
>>     { id: 1, data: 'the data', path:'/path/to/this/object'},
>>     { id: 2, data: 'more data', path: '/path/to/this/object'}
>>   ]
>>
>>   $scope.viewObject(object){
>>     $rootScope.currentObject = object;
>>     $location.path(object.path);
>>   }
>> }
>>
>> On Friday, February 28, 2014 1:10:05 AM UTC-7, Luke Kende wrote:
>>>
>>> You'll need to keep your objects referenced in a service, then use some 
>>> id that maps to the $routeParam.  Something like this:
>>>
>>> function MyService(){
>>>   var objects = [
>>>     { id: 1, data: 'the data'},
>>>     { id: 2, data: 'more data'}
>>>   ]
>>>   
>>>   return objects;
>>> }
>>>
>>> //in new route controller - this not fully fleshed-out code.... just 
>>> providing the idea
>>> var indexOfObject = MyService.indexOf($routeParams.id);
>>> $scope.object = MyService[indexOfObject];
>>>
>>> So in essence you are passing references not objects, and storing shared 
>>> data in a service.
>>>
>>>
>>> On Thursday, February 27, 2014 9:18:12 AM UTC-7, duck wrote:
>>>>
>>>> I have a list of objects in the list view, now I want to click any one 
>>>> object to take me a new page without fetching data from server, 
>>>> so the object data can be passed to the new page. I can use angularjs   
>>>> $routeParams to pass individual parameter, but not whole object. if I 
>>>> use a individual parameters to fetch data from server, it slows down the 
>>>> performance.
>>>>  
>>>> Thank you for your help!
>>>> Lily
>>>>
>>>

-- 
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/groups/opt_out.

Reply via email to