ViewUser component

Here's a minimal implementation of the <app-view-user> directive that is a prerequisite for the Review step.

Create a new viewUser component under user as shown below:

src/app/user/view-user/view-user.component.ts
import { Component, OnInit, Input } from '@angular/core'
import { IUser, User } from '../user/user'

@Component({
selector: 'app-view-user',
template: `
<mat-card>
<mat-card-header>
<div mat-card-avatar><mat-icon>account_circle</mat-icon></div>
<mat-card-title>{{currentUser.fullName}}</mat-card-title>
<mat-card-subtitle>{{currentUser.role}}</mat-card-subtitle>
</mat-card-header>
<mat-card-content>
<p><span class="mat-input bold">E-mail</span></p>
<p>{{currentUser.email}}</p>
<p><span class="mat-input bold">Date of Birth</span></p>
<p>{{currentUser.dateOfBirth | date:'mediumDate'}}</p>
</mat-card-content>
<mat-card-actions *ngIf="!this.user">
<button mat-button mat-raised-button>Edit</button>
</mat-card-actions>
</mat-card>
`,
styles: [
`
.bold {
font-weight: bold
}
`,
],
})
export class ViewUserComponent implements OnChanges {
@Input() user: IUser
currentUser = new User()

constructor() {}

ngOnChanges() {
if (this.user) {
this.currentUser = User.BuildUser(this.user)
}
}
}

The component above uses input binding with @Input to get user data, compliant with the IUser interface, from an outside component. We implement the ngOnChanges event, which fires whenever the bound data changes. In this event, we hydrate the simple JSON object stored in this.user as an instance of the class User with  User.BuildUser and assign it to this.currentUser. The template uses this variable, because calculated properties like currentUser.fullName will only work if the data resides in an instance of the class User.

Now, we are ready to complete the multi-step form.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.27.178