7.7: Adding Photo Upload in Angular
Now that we have our photo upload capability on the back-end, let's add the functionality in the Angular application.
Add PhotoEditorComponent
Inside of the members folder in the SPA project, generate a new component called PhotoEditorComponent:
Verify that it's added to app.module.ts
This will be a child component of our MemberEditComponent. So, let's add an Input property of an array of Photos to the photo-editor.component.ts
file:
PhotoEditorTemplate
Update photo-editor.component.htmls
to:
Next, add it to the MemberEditComponent where we have placeholder text of Edit photos will go here.
We'll also grab the photos to send to our PhotoEditorComponent's Input property from our MemberEditComponent's User property:
Add Styling to the Component
Let's add a custom color to our for warnings. In styles.scss
add the following:
And, in photo-editor.component.scss
, add the following style:
Add File Uploader
We're going to use another library to handle file uploading called ng2-file-upload
. It's by the same people that wrote our ngx-bootstrap library. See the docs here.
Run the following command to install the library:
Import it into the app.module.ts
file and add it to the imports array:
We'll be copying the examples from the documentation and modifying them to our needs.
In photo-editor.component.ts
, modify it to this:
Next, in our photo-editor.template.html
template, below the </div>
where we left off last time, add the following:
Wiring Up File Uploader
Now, we need to implement an initializeUploader()
method. We'll also inject the AuthService
and add the base URL from our environment
.
Test It Out
Now that we have multiple photos, we can also try out our photo carousel:
Last updated