Skip to content

Commit

Permalink
Step 14.8: Create DisplayNamePipe
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilkisiela authored and dotansimha committed Nov 27, 2016
1 parent 47930d9 commit 2ca9231
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions client/imports/app/shared/display-name.pipe.ts
@@ -0,0 +1,25 @@
import { Pipe, PipeTransform } from '@angular/core';
import { Meteor } from 'meteor/meteor';

import { User } from '../../../../both/models/user.model';

@Pipe({
name: 'displayName'
})
export class DisplayNamePipe implements PipeTransform {
transform(user: User): string {
if (!user) {
return '';
}

if (user.username) {
return user.username;
}

if (user.emails) {
return user.emails[0].address;
}

return '';
}
}

0 comments on commit 2ca9231

Please sign in to comment.