Reputation: 11
Is there any way to put a condition in the following:
<h3 ng-show="ctrl.loggedIn">
{{ctrl.loggedInUser.FirstName + " " + ctrl.loggedInUser.LastName + " is logged in."}}
</h3>
that is if the ctrl.loggedInUser.FirstName is undefined or null then it wouldn't print.
Click here to visit the project on github.
Upvotes: 1
Views: 4646
Reputation: 11
<div ng-switch on="ctrl.loggedInUser.FirstName == null || ctrl.loggedInUser.FirstName == undefined || ctrl.loggedInUser.FirstName == ''">
<h3 ng-switch-when="true">Please log in.</h3>
<h3 ng-switch-when="false">{{ctrl.loggedInUser.FirstName + " " + ctrl.loggedInUser.LastName + " is logged in."}}</h3>
</div>
this worked for me. thanks all for the ideas.
Upvotes: 0
Reputation: 31
You can use ng-show
<h3 ng-show="ctrl.loggedInUser.FirstName!=undefined || ctrl.loggedInUser.FirstName!=null">
{{ctrl.loggedInUser.FirstName + " " + ctrl.loggedInUser.LastName + " is logged in."}}
</h3>
Upvotes: 0
Reputation: 664
h3 will only show if ctrl.loggedInUser.FirstName have some value
<h3 ng-show="ctrl.loggedIn && ( ctrl.loggedInUser.FirstName!=null || (ctrl.loggedInUser.FirstName!='undefined')")>
{{ctrl.loggedInUser.FirstName + " " + ctrl.loggedInUser.LastName + " is logged in."}}
</h3>
you can also do like
<h3 ng-hide="!ctrl.loggedIn && (ctrl.loggedInUser.FirstName==null || (ctrl.loggedInUser.FirstName=='undefined')")>
{{ctrl.loggedInUser.FirstName + " " + ctrl.loggedInUser.LastName + " is logged in."}}
</h3>
Upvotes: 0
Reputation: 41377
yes you can. use ng-if
to add conditions in DOM
<h3 ng-show="ctrl.loggedIn" ng-if="ctrl.loggedInUser.FirstName">
{{ctrl.loggedInUser.FirstName + " " + ctrl.loggedInUser.LastName + " is logged in."}}
</h3>
Upvotes: 1