10.7: Adding Conversations to MemberDetailComponent
Now, we'll work on adding the message threads to the MemberDetailComponent
Adding getMessageThread() to UserService
We'll start by adding a new method getMessageThread()
to the UserService
:
Add MemberMessagesComponent
We'll add a new component to display the conversations.
Verify that it was added correctly to app.module.ts
.
Update member-messages.component.ts
to the following:
This is again very similar to what we've been doing. We do have an Input()
property for the userId
that we'll get from the MemberDetailComponent
.
In member-detail.component.html
, add the component and pass along the userId
:
Adding MemberMessages Template
And, in member-messages.component.scss
:
Navigating Directly to Messages Tab
We'd like to be able to navigate from the Messages
component to the MemberDetail
component and have the Messages
tab be open instead of the About
tab. We'd also like to open the Messages
tab when a user clicks on the Message
button in their profile panel.
We'll do this using ngx-bootstrap.
In member-detail.component.ts
, add a ViewChild()
property and a selectTab()
method:
In the member-detail.component.html
, add a click listener to the Message
button:
ngx-bootstrap
passes the tab we want as a query string and handles it for us. We're passing 3
as the parameter because it's the 4th tab (0-indexed).
Now, we'll try to do the same thing from our Messages
component. This time we'll have to pass the query parameters ourselves.
In messages.component.html
- in the second <tr>
element where we have our routerLink
set up - we can also add query parameters.
We can then subscribe to the query parameters in the ngOnInit()
method in the member-detail.component.ts
similarly to how we're getting the user query params:
We can also add this to the button with the envelope icon in our main list of users in the MemberCardComponent
. Open up member-card.component.html
and add the routerLink
and queryParams
:
Last updated