How to access an area outside of ng-view

In the navigation bar, I have a snapshot of the shopping cart (total number of items, total cost) that uses $scope.cart .

In ng-view there are pages for adding / removing items in the basket.

It seems that ng-view created an isolated area. If I add elements to $scope.cart , it goes into the area related to ng-view . How can ng-view split parent area?

+6
source share
1 answer

$scope exists inside ng-controller . The ng-view directive tells Angular JS where the partial files will be uploaded. You have several ways to archive this cart in another place outside, for example:

1) . You can create a contoller outter using $scope.cart and pass a value from the internal controller using the same variable name.

2) Another way could be to use Service , which is a singleton in Angular JS, to set up the cart, and then change it in the internal controller, for distribution to the external one.

+1
source

Source: https://habr.com/ru/post/973064/


All Articles