Let's add Selected User functionality and show the selected user details in our details container
<mat-sidenav mode="side" opened>
<mat-tab-group>
<mat-tab label="Users">
<mat-nav-list>
<mat-list-item *ngFor="let user of users" (click)="selectedUser = user">
<mat-icon matListAvatar svgIcon="avatars:{{user.avatar}}" class="avatar"></mat-icon>
<span>{{user.name}}</span>
</mat-list-item>
</mat-nav-list>
</mat-tab>
<mat-tab label="Settings">
<span>Settings</span>
</mat-tab>
</mat-tab-group>
</mat-sidenav>
<div class="content">
<mat-icon svgIcon="avatars:{{selectedUser.avatar}}" class="avatar"></mat-icon>
<h2>{{selectedUser.name}}</h2>
<p>{{selectedUser.details}}</p>
</div>
Let's select the first user from the users list for our initial view state
import {Component} from '@angular/core';
import {MatIconRegistry} from '@angular/material';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
users = [
{
name: 'Lia Lugo',
avatar: 'svg-11',
details: 'I love cheese, ...',
isAdmin: true,
isCool: false
},
{
name: 'George Duke',
avatar: 'svg-12',
details: 'Zombie ipsum ...',
isAdmin: false,
isCool: true
}
// ...
];
selectedUser = this.users[0];
...
}
.content {
padding: 12px;
}