Permalink
Browse files

Step 14.8: Create DisplayNamePipe

  • Loading branch information...
1 parent 11002d6 commit 70fa057f090ac155e9d2085b25089169a6c69319 @kamilkisiela kamilkisiela committed with DAB0mB Sep 23, 2016
Showing with 25 additions and 0 deletions.
  1. +25 −0 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 70fa057

Please sign in to comment.