5.10: Adding Photo Gallery

Let's add a photo gallery to our Photos tab.

To do this we'll use another library: ngx-gallery.

Read the docs if you would like to customize it.

In the root of your SPA project, run the following command:

npm install ngx-gallery --save

Import it into your app.module.ts file and add it to the imports array:

import { NgxGalleryModule } from 'ngx-gallery';

//  ...

imports: [
    BrowserModule,
    FormsModule,
    HttpClientModule,
    NgxGalleryModule,

//  ...

Next, open up the member-detail.component.ts file and start by adding two properties:

Next, specify the options and the images in ngOnInit():

And, finally, we'll implement the getImages() method to populate an array according to what ngx-gallery is expecting.

In member-detail.component.html, currently we have a <p> with "Photos will go here."

Replace that with the following ngx-gallery directive:

Right now, it doesn't have much functionality. But, it will improve once we have a way for users to add more photos. Coming soon!

Last updated