1

I just started with AngularJS, So my question might be very basic.

I have a link in one view, which once clicked calls a service, gets the data. In the controller i am changing the view using $location and updating the new view with the data i got from service. The view is changing fine, But i am having issue updating the data. Below is my code.

First View:

<a class="red"  ng-href='#RestaurantDetails' ng-click='restaurantDetails()'>
   {{restaurant.name}}
</a>

Controller:

$scope.restaurantDetails = function()
{
    fpServices.loadRestaurantDetails(function(event){
        $scope.restaurantInfo = event;
        $scope.restaurantId = event[0].id;
        $location.path('/restaurant_details/'+$scope.restaurantId);
    });
};

'restaurantInfo' is an object i am getting from service.

Second View:

{{restaurantInfo.name}}

Tried ng-repeat too with no luck. Any help would be greatly appreciated!

1 Answer 1

1

Since you are setting you content on the first view scope you cannot access it from a different view scope.

What you can do is use the $rootScope and set the property like activeRestaurant such as

$rootScope.activeRestaurant=event;

and then can access this in the other view. Remember to inject $rootScope in both the views.

The better way would be to create a service, to set active restaurant and call it from one view to set the restaurant and from another to get the active restaurant.

Sign up to request clarification or add additional context in comments.

1 Comment

Setting $rootScope worked like a charm!..Thanks @Chandermani.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.