AngularJS Print Yes or No based on boolean
4 answers
Try not to put JS operations in your template as this will:
- Make your template dirty (imho).
- Extract the application (very minor argument) as the evaluation is done in every loop
$digest
.
If you are ok with modifying the bool
patient's original :
$scope.patient.Alcoholic = !!$scope.patient.Alcoholic ? 'Yes' : 'No';
If not, I would add another property to patient
:
$scope.patient.isAlcoholic = !!$scope.patient.Alcoholic ? 'Yes' : 'No';
And then in your opinion (depending on the solution you chose from the two above):
{{ patient.Alcoholic }}
<!-- or -->
{{ patient.isAlcoholic }}
That's my two cents for keeping your template clean.
+1
source to share