/capacitor-frameworks:capacitor-angularfrom capacitor-frameworks
Guides Angular-specific patterns for Capacitor app development: project structure, plugin usage in services/components, change detection with signals and NgZone, lifecycle hooks, dependency injection, deep link routing, live reload, and platform detection.
Ships in capacitor-frameworks. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Angular-specific patterns and best practices for Capacitor app development — project structure, services, lifecycle hooks, change detection, and plugin usage.
@angular/cli in package.json). Run it with npx ng. A global install is not needed.The code examples in this skill use the APIs of Angular 19 and later: standalone components without the standalone flag, the @if block, signals, and provideAppInitializer. For a project on Angular 16, 17 or 18, read references/older-angular-versions.md and adapt the examples.
angular.json, package.json, capacitor.config.ts or capacitor.config.json, and existing directory structure. Only ask the user when something cannot be detected.app.ts and app.html. Older versions generate app.component.ts and app.component.html.Auto-detect the following by reading project files:
@angular/core version from package.json.@capacitor/core version from package.json. If not present, Capacitor has not been added yet — proceed to Step 2.src/main.ts for bootstrapApplication (standalone) vs. platformBrowserDynamic().bootstrapModule (NgModule). Check angular.json for further confirmation.zone.js is listed in the polyfills array of the build target in angular.json, or if the providers contain provideZoneChangeDetection(). Otherwise it is zoneless. Zoneless is the default since Angular 21. On Angular 20 it needs provideZonelessChangeDetection() in the providers.android/, ios/).capacitor.config.ts (TypeScript) or capacitor.config.json (JSON).outputPath from angular.json under projects > <project-name> > architect > build > options > outputPath. If the option is missing, the default is dist/<project-name>. With the application builder (@angular/build:application or @angular-devkit/build-angular:application) the web files are in the subfolder browser. This is needed for Capacitor's webDir setting.Skip if @capacitor/core is already in package.json.
Install Capacitor core and CLI in version 8:
npm install @capacitor/core@8
npm install -D @capacitor/cli@8
Always name the version 8. Do not use the latest tag and do not leave the version out. Both can install a newer major version than this skill covers.
Initialize Capacitor. Pass the app name, the app ID and the web directory. Without them the CLI asks for them in the terminal. Ask the user for the app name and the app ID (reverse-domain format, e.g. com.example.app):
npx cap init "<appName>" <appId> --web-dir dist/<project-name>/browser
Use the Angular build output path detected in Step 1 as the web directory. For Angular 17+ with the application builder, this is typically dist/<project-name>/browser. For older Angular versions, it is typically dist/<project-name>.
Verify the webDir value in the generated capacitor.config.ts or capacitor.config.json matches the Angular build output path. If incorrect, update it:
capacitor.config.ts:
import type { CapacitorConfig } from '@capacitor/cli';
const config: CapacitorConfig = {
appId: 'com.example.app',
appName: 'my-app',
webDir: 'dist/my-app/browser',
};
export default config;
capacitor.config.json:
{
"appId": "com.example.app",
"appName": "my-app",
"webDir": "dist/my-app/browser"
}
Build the Angular app and add platforms:
npx ng build
npm install @capacitor/android@8 @capacitor/ios@8
npx cap add android
npx cap add ios
npx cap sync
Capacitor needs static web files with an index.html in the web directory. If the project uses server-side rendering (@angular/ssr in package.json), check that the file dist/<project-name>/browser/index.html exists after the build. If it does not exist, tell the user that the app must be built as a client-side app for Capacitor.
A Capacitor Angular project has this structure:
my-app/
├── android/ # Android native project
├── ios/ # iOS native project
├── src/
│ ├── app/
│ │ ├── app.ts # Root component (app.component.ts before Angular 20)
│ │ ├── app.config.ts # Standalone: app configuration
│ │ ├── app.module.ts # NgModule: root module
│ │ ├── app.routes.ts # Routing configuration
│ │ └── services/ # Angular services for Capacitor plugins
│ ├── index.html
│ └── main.ts
├── angular.json
├── capacitor.config.ts # or capacitor.config.json
├── package.json
└── tsconfig.json
Key points:
android/ and ios/ directories contain native projects and should be committed to version control.src/ directory contains the Angular app, which is the web layer of the Capacitor app.src/app/.Capacitor plugins are plain TypeScript APIs. Import and call them directly in Angular components or services.
Install an official @capacitor/* plugin in the major version of @capacitor/core of the project, for example npm install @capacitor/geolocation@8 in a Capacitor 8 project. Do not use the latest tag and do not leave the version out. Both can install a plugin for a newer Capacitor major version. Then run npx cap sync.
Store every value that a template shows in a signal. A plugin call is asynchronous. In a zoneless app, a plain class property that is set after an await does not update the template.
import { Component, signal } from '@angular/core';
import { Geolocation } from '@capacitor/geolocation';
@Component({
selector: 'app-location',
template: `
<div>
<p>Latitude: {{ latitude() }}</p>
<p>Longitude: {{ longitude() }}</p>
<button (click)="getCurrentPosition()">Get Location</button>
</div>
`,
})
export class LocationComponent {
readonly latitude = signal<number | null>(null);
readonly longitude = signal<number | null>(null);
async getCurrentPosition() {
const position = await Geolocation.getCurrentPosition();
this.latitude.set(position.coords.latitude);
this.longitude.set(position.coords.longitude);
}
}
Wrapping Capacitor plugins in Angular services provides dependency injection, testability, and a single place to handle platform differences:
import { Injectable } from '@angular/core';
import { Camera } from '@capacitor/camera';
import type { MediaResult } from '@capacitor/camera';
import { Capacitor } from '@capacitor/core';
@Injectable({
providedIn: 'root',
})
export class CameraService {
async takePhoto(): Promise<MediaResult> {
return Camera.takePhoto({ quality: 90 });
}
async pickFromGallery(): Promise<MediaResult | undefined> {
const { results } = await Camera.chooseFromGallery({ quality: 90 });
return results[0];
}
isNativePlatform(): boolean {
return Capacitor.isNativePlatform();
}
}
Camera.takePhoto() and Camera.chooseFromGallery() need @capacitor/camera 8.1.0 or later. This version deprecated Camera.getPhoto() and Camera.pickImages(). If the project has an older version of the plugin, use Camera.getPhoto({ quality: 90, resultType: CameraResultType.Uri, source: CameraSource.Camera }), which returns a Photo.
Use the service in a component:
import { Component, inject, signal } from '@angular/core';
import { CameraService } from '../services/camera.service';
@Component({
selector: 'app-photo',
template: `
<button (click)="takePhoto()">Take Photo</button>
@if (photoUrl(); as url) {
<img [src]="url" alt="Captured photo" />
}
`,
})
export class PhotoComponent {
private cameraService = inject(CameraService);
readonly photoUrl = signal<string | null>(null);
async takePhoto() {
const photo = await this.cameraService.takePhoto();
this.photoUrl.set(photo.webPath ?? null);
}
}
Capacitor calls the callback of a plugin event listener from native code. The callback runs outside Angular's NgZone. Angular does not notice a plain class property that the callback changes, and the template does not update.
Rule: Store state that a plugin listener changes in a signal, and update the signal inside NgZone.run(). The two parts cover the two change detection modes:
NgZone.run() does not trigger change detection there. It only runs the function.NgZone.run() brings the callback back into Angular's zone, and Angular runs change detection when the callback ends.Code that uses both is correct in both modes and keeps working when the app moves from zone-based to zoneless.
import { Component, NgZone, OnDestroy, OnInit, inject, signal } from '@angular/core';
import { Network } from '@capacitor/network';
import type { PluginListenerHandle } from '@capacitor/core';
@Component({
selector: 'app-network',
template: `<p>Status: {{ networkStatus() }}</p>`,
})
export class NetworkComponent implements OnInit, OnDestroy {
private ngZone = inject(NgZone);
readonly networkStatus = signal('Unknown');
private listenerHandle: PluginListenerHandle | null = null;
async ngOnInit() {
const status = await Network.getStatus();
this.networkStatus.set(status.connected ? 'Online' : 'Offline');
this.listenerHandle = await Network.addListener('networkStatusChange', (status) => {
this.ngZone.run(() => {
this.networkStatus.set(status.connected ? 'Online' : 'Offline');
});
});
}
async ngOnDestroy() {
await this.listenerHandle?.remove();
}
}
If existing code keeps the state in a plain class property, choose by the change detection mode from Step 1:
| Mode | What to do in the listener callback |
|---|---|
| Zoneless | Change the property to a signal. If the property cannot be changed, inject ChangeDetectorRef and call markForCheck() after the update. |
| Zone-based | Wrap the update in NgZone.run(): this.ngZone.run(() => { this.networkStatus = 'Online'; });. |
In a zoneless app, the NgZone.run() wrapper can be left out. Existing NgZone.run() calls do not need to be removed when an app moves to zoneless.
Use Angular lifecycle hooks to manage Capacitor plugin listeners. Register listeners in ngOnInit and remove them in ngOnDestroy to prevent memory leaks.
For app-wide listeners (e.g., network status, app state), use a service initialized at app startup:
import { Injectable, NgZone, OnDestroy, inject, signal } from '@angular/core';
import { App } from '@capacitor/app';
import type { PluginListenerHandle } from '@capacitor/core';
@Injectable({
providedIn: 'root',
})
export class AppStateService implements OnDestroy {
private ngZone = inject(NgZone);
private listenerHandle: PluginListenerHandle | null = null;
private readonly isActiveState = signal(true);
readonly isActive = this.isActiveState.asReadonly();
constructor() {
this.initListener();
}
private async initListener() {
this.listenerHandle = await App.addListener('appStateChange', (state) => {
this.ngZone.run(() => {
this.isActiveState.set(state.isActive);
});
});
}
async ngOnDestroy() {
await this.listenerHandle?.remove();
}
}
Initialize the service at app startup to ensure it runs immediately. In standalone apps, use provideAppInitializer or inject it in the root component. In NgModule apps, inject it in AppComponent:
Standalone (app.config.ts):
import { ApplicationConfig, inject, provideAppInitializer } from '@angular/core';
import { AppStateService } from './services/app-state.service';
export const appConfig: ApplicationConfig = {
providers: [
provideAppInitializer(() => {
inject(AppStateService);
}),
],
};
provideAppInitializer exists since Angular 19. The token APP_INITIALIZER is deprecated since Angular 19. Do not use it in new code.
NgModule (app.component.ts):
import { Component, inject } from '@angular/core';
import { AppStateService } from './services/app-state.service';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
standalone: false,
})
export class AppComponent {
private appStateService = inject(AppStateService);
}
Use Capacitor.isNativePlatform() and Capacitor.getPlatform() to conditionally run native-only code:
import { Injectable } from '@angular/core';
import { Capacitor } from '@capacitor/core';
@Injectable({
providedIn: 'root',
})
export class PlatformService {
isNative(): boolean {
return Capacitor.isNativePlatform();
}
getPlatform(): 'web' | 'ios' | 'android' {
return Capacitor.getPlatform() as 'web' | 'ios' | 'android';
}
isIos(): boolean {
return Capacitor.getPlatform() === 'ios';
}
isAndroid(): boolean {
return Capacitor.getPlatform() === 'android';
}
isWeb(): boolean {
return Capacitor.getPlatform() === 'web';
}
}
Use it in components to show/hide native-only features:
import { Component, inject } from '@angular/core';
import { PlatformService } from '../services/platform.service';
@Component({
selector: 'app-settings',
template: `
@if (platformService.isNative()) {
<button (click)="openNativeSettings()">Open Device Settings</button>
}
`,
})
export class SettingsComponent {
platformService = inject(PlatformService);
openNativeSettings() {
// Native-only logic
}
}
Handle deep links by mapping Capacitor's App.addListener('appUrlOpen', ...) event to Angular Router navigation. Read references/deep-links-and-back-button.md for the service (DeepLinkService) and for how to initialize it at app startup.
Keep the navigation inside NgZone.run(), as the reference shows.
Handle the Android hardware back button using App.addListener('backButton', ...). Read references/deep-links-and-back-button.md for the service (BackButtonService).
Check canGoBack before calling App.exitApp().
After making changes to the Angular app, build and sync to native platforms:
npx ng build
npx cap sync
To run on a device or emulator, list the targets first and pass one ID. Without --target the CLI asks for a device in the terminal when more than one is available:
npx cap run android --list
npx cap run android --target <android-target-id>
npx cap run ios --list
npx cap run ios --target <ios-target-id>
To open the native IDE for advanced configuration or debugging:
npx cap open android
npx cap open ios
The Capacitor CLI does not start the Angular dev server. Start it first and bind it to all network interfaces. The command keeps running, so start it in a second terminal or as a background process:
npx ng serve --host 0.0.0.0 --port 4200
Find the IP address of the computer in the local network (macOS: ipconfig getifaddr en0, Windows: ipconfig). The device must be in the same network. Then run the app with the host and the port of the dev server:
npx cap run android --live-reload --host <ip-address> --port 4200 --target <android-target-id>
npx cap run ios --live-reload --host <ip-address> --port 4200 --target <ios-target-id>
The options --livereload and --external belong to the Ionic CLI (ionic cap run). The Capacitor CLI does not have them.
NgZone.run(() => { ... }). In a zoneless app, change the state from a plain class property to a signal (Step 5). This is the most common Angular-specific issue with Capacitor.webDir mismatch: If npx cap sync copies the wrong files, verify that webDir in capacitor.config.ts or capacitor.config.json matches the Angular build output path. For Angular 17+ with the application builder, the path is dist/<project-name>/browser. For older Angular versions, it is dist/<project-name>.npx cap sync after installing any new plugin. Verify the plugin appears in package.json dependencies.ngOnDestroy. Store the PluginListenerHandle returned by addListener and call handle.remove() on destroy.android/app/src/main/AndroidManifest.xml for Android, ios/App/App/Info.plist and associated domain entitlement for iOS). Verify DeepLinkService is initialized at app startup.canGoBack before calling App.exitApp(). Only exit when there is no navigation history.npx ng build: Verify the outputPath in angular.json is correct. For Angular 17+, the default changed to dist/<project-name>/browser with the application builder.npx cap run fails with an unknown option --livereload or --external: These are options of the Ionic CLI. Use the commands in the Live Reload section of Step 10.Camera.takePhoto is not a function: The installed @capacitor/camera is older than 8.1.0. In a Capacitor 8 project, update the plugin with npm install @capacitor/camera@8 and run npx cap sync. In a Capacitor 6 or 7 project, use Camera.getPhoto().capacitor-app-creation — Create a new Capacitor app from scratch.capacitor-app-development — General Capacitor development guidance not specific to Angular.capacitor-plugins — Install and configure Capacitor plugins from official and community sources.capacitor-react — React-specific patterns and best practices for Capacitor app development.capacitor-vue: Vue-specific patterns and best practices for Capacitor app development.ionic-angular — Ionic Framework with Angular (UI components, navigation, theming on top of Capacitor).capacitor-app-upgrades — Upgrade a Capacitor app to a newer major version.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub capawesome-team/skills --plugin capacitor-frameworks3 skills in this plugin
/capacitor-reactGuides the agent through Capacitor app development with React — project structure, hooks for native features, state management patterns, using Capacitor plugins in React components, and React-specific best practices. Do not use for Ionic Framework with React (use ionic-react), migrating or upgrading Capacitor apps or plugins, or non-React frameworks./capacitor-vueGuides the agent through Vue-specific patterns for Capacitor app development. Covers Vue 3 Composition API with Capacitor plugins, custom composables for native features, reactive plugin state, lifecycle hook patterns, Vue Router deep link integration, platform detection, PWA Elements setup, Quasar Framework integration, and Nuxt integration. Do not use for creating a new Capacitor app from scratch, upgrading Capacitor versions, installing specific plugins, Ionic Framework with Vue setup, or non-Vue frameworks.Other plugins' skills for the same job