Skip to content

Commit dc6764c

Browse files
committed
docs(angular): update the your first app pages
1 parent 7714f0e commit dc6764c

File tree

4 files changed

+9
-12
lines changed

4 files changed

+9
-12
lines changed

docs/angular/your-first-app.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ We'll create a Photo Gallery app that offers the ability to take photos with you
3434

3535
Highlights include:
3636

37-
- One Angular-based codebase that runs on the web, iOS, and Android using Ionic Framework [UI components](https://ionicframework.com/docs/components).
37+
- One Angular-based codebase that runs on the web, iOS, and Android using Ionic Framework [UI components](../components.md).
3838
- Deployed as a native iOS and Android mobile app using [Capacitor](https://capacitorjs.com), Ionic's official native app runtime.
39-
- Photo Gallery functionality powered by the Capacitor [Camera](https://capacitorjs.com/docs/apis/camera), [Filesystem](https://capacitorjs.com/docs/apis/filesystem), and [Preferences](https://capacitorjs.com/docs/apis/preferences) APIs.
39+
- Photo Gallery functionality powered by the Capacitor [Camera](../native/camera.md), [Filesystem](../native/filesystem.md), and [Preferences](../native/preferences.md) APIs.
4040

4141
Find the complete app code referenced in this guide [on GitHub](https://github.com/ionic-team/photo-gallery-capacitor-ng).
4242

@@ -114,7 +114,7 @@ import { AppModule } from './app/app.module';
114114
// CHANGE: Add the following import.
115115
import { defineCustomElements } from '@ionic/pwa-elements/loader';
116116

117-
// Call the element loader before the `bootstrapModule` call.
117+
// CHANGE: Call the element loader before the `bootstrapModule` call.
118118
defineCustomElements(window);
119119

120120
platformBrowserDynamic()

docs/angular/your-first-app/2-taking-photos.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ sidebar_label: Taking Photos
1111
/>
1212
</head>
1313

14-
Now for the fun part - adding the ability to take photos with the device’s camera using the Capacitor [Camera API](https://capacitorjs.com/docs/apis/camera). We’ll begin with building it for the web, then make some small tweaks to make it work on mobile (iOS and Android).
14+
Now for the fun part - adding the ability to take photos with the device’s camera using the Capacitor [Camera API](../../native/camera.md). We’ll begin with building it for the web, then make some small tweaks to make it work on mobile (iOS and Android).
1515

1616
## Photo Service
1717

@@ -147,9 +147,10 @@ export class PhotoService {
147147
}
148148
```
149149

150-
Over in the `addNewToGallery` method, add the newly captured photo to the beginning of the Photos array.
150+
Over in the `addNewToGallery` method, add the newly captured photo to the beginning of the `photos` array.
151151

152152
```ts
153+
// CHANGE: Update `addNewToGallery()` method.
153154
public async addNewToGallery() {
154155
const capturedPhoto = await Camera.getPhoto({
155156
resultType: CameraResultType.Uri,
@@ -169,7 +170,6 @@ public async addNewToGallery() {
169170

170171
```ts
171172
import { Injectable } from '@angular/core';
172-
// CHANGE: Add the following imports.
173173
import { Camera, CameraResultType, CameraSource, Photo } from '@capacitor/camera';
174174
import { Filesystem, Directory } from '@capacitor/filesystem';
175175
import { Preferences } from '@capacitor/preferences';
@@ -178,10 +178,8 @@ import { Preferences } from '@capacitor/preferences';
178178
providedIn: 'root',
179179
})
180180
export class PhotoService {
181-
// CHANGE: Add the photos array.
182181
public photos: UserPhoto[] = [];
183182

184-
// CHANGE: Add the gallery function.
185183
public async addNewToGallery() {
186184
// Take a photo
187185
const capturedPhoto = await Camera.getPhoto({
@@ -190,15 +188,13 @@ export class PhotoService {
190188
quality: 100,
191189
});
192190

193-
// CHANGE: Add the new photo to the photos array.
194191
this.photos.unshift({
195192
filepath: 'soon...',
196193
webviewPath: capturedPhoto.webPath!,
197194
});
198195
}
199196
}
200197

201-
// CHANGE: Add the interface.
202198
export interface UserPhoto {
203199
filepath: string;
204200
webviewPath?: string;

docs/angular/your-first-app/3-saving-photos.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import { Preferences } from '@capacitor/preferences';
5252
export class PhotoService {
5353
public photos: UserPhoto[] = [];
5454

55+
// CHANGE: Update `addNewToGallery()` method.
5556
public async addNewToGallery() {
5657
// Take a photo
5758
const capturedPhoto = await Camera.getPhoto({

docs/angular/your-first-app/5-adding-mobile.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export class PhotoService {
4242

4343
## Platform-specific Logic
4444

45-
First, we’ll update the photo saving functionality to support mobile. In the `readAsBase64()` function, check which platform the app is running on. If it’s “hybrid” (Capacitor or Cordova, two native runtimes), then read the photo file into base64 format using the `Filesystem`'s' `readFile()` method. Otherwise, use the same logic as before when running the app on the web.
45+
First, we’ll update the photo saving functionality to support mobile. In the `readAsBase64()` method, check which platform the app is running on. If it’s “hybrid” (Capacitor or Cordova, two native runtimes), then read the photo file into base64 format using the `Filesystem`'s' `readFile()` method. Otherwise, use the logic as before when running the app on the web.
4646

4747
Update `readAsBase64()` to look like the following:
4848

@@ -106,7 +106,7 @@ private async savePicture(photo: Photo) {
106106
}
107107
```
108108

109-
Next, head back over to the `loadSaved()` method we implemented for the web earlier. On mobile, we can directly set the source of an image tag - `<img src="x" />` - to each photo file on the `Filesystem`, displaying them automatically. Thus, only the web requires reading each image from the `Filesystem` into base64 format. Update this method to add an _if statement_ around the `Filesystem` code:
109+
Next, add a new bit of logic in the `loadSaved()` method. On mobile, we can directly point to each photo file on the Filesystem and display them automatically. On the web, however, we must read each image from the Filesystem into base64 format. This is because the Filesystem API uses [IndexedDB](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API) under the hood. Update the `loadSaved()` method:
110110

111111
```ts
112112
// CHANGE: Update `loadSaved` method.

0 commit comments

Comments
 (0)