Suppose I have a variable in the $scope:
$scope.smsProfile.Active
which can be true or false and I would like to display a text on the screen with respect to it's value. For example if it is true display "Profile active" and if it is false display "Profile not active". How can I do that?
I tried like this:
{{true:'Profile active', false:'Profile not active'}[$scope.smsProfile.Active]}
but it doesn't work.
Use ng-hide and/or ng-show directive:
<span ng-show="smsProfile.Active">Profile active</span>
<span ng-hide="smsProfile.Active">Profile not active</span>
Add a method in controller:
$scope.smsProfile= {
Active: true,
statusText: function () {
return $scope.foo.Active ? 'active' : 'not active';
}
}
Then output the method in an expression or ng-bind
<span>Profile is {{smsProfile.statusText()}}</span>