D
D
DarthJS2016-01-04 12:56:22
Angular
DarthJS, 2016-01-04 12:56:22

How to update View from another scope?

The essence of the problem:
I have a test registration form using LocalStorage. After the user registers, the data enters the local store, the user is redirected to the user's page and the menu changes according to the rules ng-if. And so View does not change, only it is shown that the link is new. But when you press F5, when the controller is triggered, naturally everything is normal.
Details:
1. service ` Authentication`. A method that puts the form data in ` localStorage` and redirects the user to another link:

Authentication.registration = function(data) {
       localStorage.setItem('registrationData', JSON.stringify(data));
       $location.path('/userPage');
     }
     Authentication.ifLog = function() {
       // verify if the user exists in localStorage
     }

2. popup registration form window and its methods in function ` Link`:
$scope.registration = function(form) {
         Authentication.registration(
         };

3. Menu items with conditions. When the user is logged in, we show him the 1st and 3rd menu items and transfer to a new page.
'` Base`' is the controller where I call the ifLogservice ` ` method ` Authentication` .
<li ng-if="Base.logined"><a href="#userPage">UserPage</a></li>
    <li ng-if="!Base.logined" ng-click="Base.toggleModal()">LogIn</li>
    <li ng-if="Base.logined">{{Base.user.name}}</li>

what needs to be done to update viewxy?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nicholas, 2016-01-04
@healqq

Well, you probably need to call the ifLog method again after registration and update the Base.logined value. Well, or in the ng-if itself, call the function, and not check the property.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question