I am currently working on a feature to display whether a user is active or not based on data retrieved from an API in Boolean form. The API returns 'true' if the user is active and 'false' if not. To achieve this, I initially implemented a simple if-else statement which served its purpose. However, considering its frequent usage across the application, I have decided to create an angular filter to handle this task more efficiently. As a beginner in Angular and JavaScript, creating a filter is new territory for me.
This is how I currently implement the if-else logic in HTML:
<label>{{ $ctrl.myValu | truefalse}}</label>
$onInit = () => {
let self = this;
this.siUser.current().then((userData) => {
let actingAsTenant = userData.user.apikey;
if (actingAsTenant) {
self.siTenant.current().then((tenant) => {
self.tenant = tenant;
///starts
if (self.tenant.active == true) {
self.tenant.active = 'Active'
}
else if (self.tenant.active == false){
self.tenant.active = 'Not Active'
}
//end
}, (err) => {
self.siAlertDialog.error(err.data.message)
})
}
}, (err) => {
self.siAlertDialog.error('Error rendering tenant details');
});
}
<strong>{{$ctrl.tenant.active}}</strong>