Question

Sorry if this question seems stupid. I'm making a kind of migration from javascriptmvc to angularjs. There is some point that is not exactly clear to me. Can I apply conditional statements on html with angularjs? Lets say I build the page depending on user login state. If user is logged in I hide login controls and show some welcome message. If user is not logged in then I show login controls. With javascriptmvc I can solve this with simply creating 2 different views and appending them according to data received - each view for each situation I described. It is easier because the controller is the entry point for the html building process and not the html. Something like

<% if (data.logged_in){%>
 <div>
...some markup...
</div>
<%} else {%>
 <div>
...another markup...
</div>
<%}%>

How can I do such thing with angular?

Was it helpful?

Solution

In the latest version of Angular.js you can use this.

<div ng-if="{expression}">
   ..Some Markup ...
</div>

in previous versions (1.0.7)

<div ng-show="{expression}">
   ..Some Markup ...
</div>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top