0

I'm trying to figure out the best patter for applying when writing a particular type of Angular directive. In this scenario, I want it to display a login form if a user is logged out, and then switch to a different view once logged in.

This isn't my complete app, so it's not a redirect as far as I can see. The specific example at the moment is that up in the top right of the page will be a last.fm login form, which will switch over to a last.fm widget if the user successfully logs in.

I could put both in the template and change them dynamically with CSS, but this somehow feels a little off. Can I swap a directive's entire template and recompile? Should I use two divs with ng-if statements?

I'm sure there are many ways of doing it, but is there a particularly Angular way of handling the situation?

0

I'd use 2 different divs as you say with ng-if. That is the desired behavior anyway... you essentially have 2 "mini views" (one logged in and one not) with separate functionality for this widget.

I wouldn't try to get fancy here for no reason.

1
  • 1
    That makes sense. They should both be small as well, so it should be clear that the template contains two views. – chooban Feb 10 '15 at 12:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.