1

I have a login system maded with AngularJS. Now I want that if somebody is not logged in the template is blank. If somebody logs in the template will continue. The problem is that when you load the page the templates loads also. So when you log in you get a blank page, you need the reload the page and then its working.

Is there a function that refresh the template? So that you don`t have to reload the page?

1 Answer 1

1

When you use Angular it's best to have the web server serve static content (images, css, js, and static html) and data (almost always JSON).

In your case I would always serve the template and use ng-show and/or ng-hide to toggle the template display. Here's a simple example:

Instead of

<?php
  echo "Hello " + $name;
?>

Do this

greeting.html

<div ng-show="authenticated">{{name}}</div>

greeting.json web service (I'm not a php person, my php might not be entirely correct):

<?php 
  json_encode($name) 
?>
Sign up to request clarification or add additional context in comments.

4 Comments

The server will not return data that it shouldn't. ng-show is fine.
Hmm, thats smart. But how to create authenticated? Thats a directive right?
It's just a property that you would set on $scope or $rootScope. So in the callback of successful authentication, $scope.authenticated = true. You determine when a user is authenticated.
The front end doesn't need to be "secure" except through TLS to prevent MITM injections. BTW, cookie injections are possible even with a secure connection.

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.