Frameworks
@skyscribe-sdk/angular ships two APIs. Choose based on your component style:
| API | Style | Returns |
|---|---|---|
ScribeService | RxJS / async pipe | Cold Observables: the fetch starts on subscribe and is cancelled on unsubscribe |
injectPublication / injectDocumentBySlug / injectDocument | Angular Signals | Readonly signals: the fetch starts immediately and is cancelled when the component is destroyed |
npm install @skyscribe-sdk/angular
Requires Angular 16 or later.
ScribeServiceScribeService is provided in the root injector. Use it with the async pipe for the most concise result.
Document pages usually have the Document's slug from the route, so the examples use getDocumentBySlug and injectDocumentBySlug, which look the slug up in the Publication and return the Document (its uri is its AT URI).
import { Component, inject } from '@angular/core';
import { AsyncPipe, NgIf, NgFor } from '@angular/common';
import { ScribeService } from '@skyscribe-sdk/angular';
@Component({
standalone: true,
imports: [AsyncPipe, NgIf, NgFor],
template: `
<ng-container *ngIf="publication$ | async as publication">
<h1>{{ publication.name }}</h1>
<section *ngFor="let category of publication.categories">
<h2>{{ category.title }}</h2>
<ul>
<li *ngFor="let ref of category.documents">{{ ref.title }}</li>
</ul>
</section>
</ng-container>
`,
})
export class BlogComponent {
publication$ = inject(ScribeService).getPublication('alice.bsky.social', 'https://alice.bsky.social');
}
import { Component, inject } from '@angular/core';
import { AsyncPipe, NgIf } from '@angular/common';
import { ActivatedRoute } from '@angular/router';
import { ScribeService } from '@skyscribe-sdk/angular';
@Component({
standalone: true,
imports: [AsyncPipe, NgIf],
template: `
<ng-container *ngIf="document$ | async as doc">
<h1>{{ doc.title }}</h1>
<div class="scribe-content" [innerHTML]="doc.content"></div>
</ng-container>
`,
})
export class DocumentComponent {
private slug = inject(ActivatedRoute).snapshot.paramMap.get('slug')!;
document$ = inject(ScribeService).getDocumentBySlug(
'alice.bsky.social',
'https://alice.bsky.social',
this.slug,
);
}
The fetch is cancelled automatically when you unsubscribe or when the async pipe's host component is destroyed.
injectPublication / injectDocumentBySlugThe injection functions return readonly signals: { publication, loading, error }, or { document, loading, error } for injectDocumentBySlug. The fetch is aborted when the host component is destroyed.
import { Component } from '@angular/core';
import { NgIf, NgFor } from '@angular/common';
import { injectPublication } from '@skyscribe-sdk/angular';
@Component({
standalone: true,
imports: [NgIf, NgFor],
template: `
<p *ngIf="vm.loading()">Loading…</p>
<p *ngIf="vm.error()">{{ vm.error()!.message }}</p>
<ng-container *ngIf="vm.publication() as publication">
<h1>{{ publication.name }}</h1>
<section *ngFor="let category of publication.categories">
<h2>{{ category.title }}</h2>
</section>
</ng-container>
`,
})
export class BlogComponent {
vm = injectPublication('alice.bsky.social', 'https://alice.bsky.social');
}
import { Component, inject } from '@angular/core';
import { NgIf } from '@angular/common';
import { ActivatedRoute } from '@angular/router';
import { injectDocumentBySlug } from '@skyscribe-sdk/angular';
@Component({
standalone: true,
imports: [NgIf],
template: `
<p *ngIf="vm.loading()">Loading…</p>
<article *ngIf="vm.document() as doc">
<h1>{{ doc.title }}</h1>
<div class="scribe-content" [innerHTML]="doc.content"></div>
</article>
`,
})
export class DocumentComponent {
vm = injectDocumentBySlug(
'alice.bsky.social',
'https://alice.bsky.social',
inject(ActivatedRoute).snapshot.paramMap.get('slug')!,
);
}
Note
Injection functions must be called in an injection context: a constructor or a class field initialiser. They can't be called inside lifecycle hooks or event handlers.
If you already have a DocumentRef, getDocument(author, rkey) and injectDocument(author, rkey) skip the Publication lookup. They take the Document's account and record key (rkey), both in DocumentRef.uri: the account is ref.uri.split('/')[2] and the rkey is slugFromUri(ref.uri) (from @skyscribe-sdk/core). Don't pass a slug: Documents published with current tooling have opaque rkeys, so a slug only finds very old Documents.
Angular sanitises values bound to [innerHTML], removing scripts and other unsafe markup, so Document content is safe to bind directly. The scribe-content class lets @skyscribe-sdk/styles style it.
injectPublicationUri / injectDocumentUri@skyscribe-sdk/social's buttons are React components, so you can't use them in an Angular template. If you're building your own like or subscribe UI, injectPublicationUri and injectDocumentUri resolve just the AT URI you need (ScribeService has matching getPublicationUri / getDocumentUri methods). injectDocumentUri takes the Document's slug:
import { Component } from '@angular/core';
import { NgIf } from '@angular/common';
import { injectDocumentUri } from '@skyscribe-sdk/angular';
@Component({
standalone: true,
imports: [NgIf],
template: `<p *ngIf="uri.uri() as documentUri">AT URI: {{ documentUri }}</p>`,
})
export class DocumentUriComponent {
uri = injectDocumentUri('alice.bsky.social', 'https://alice.bsky.social', 'my-first-post');
}
Show the Publication's owner visit figures on its Insights tab in SkyScribe (free, cookie-free):
// Once, in AppComponent's constructor
import { PLATFORM_ID, inject } from '@angular/core';
import { isPlatformBrowser } from '@angular/common';
import { loadSiteAnalytics } from '@skyscribe-sdk/core';
if (isPlatformBrowser(inject(PLATFORM_ID))) loadSiteAnalytics();
Figures only appear once your website serves the Publication verification file. See the Site Analytics guide for that, privacy, and CSP.
The main types from @skyscribe-sdk/core are re-exported:
import type { StandardPublication, StandardDocument, DocumentRef, Category } from '@skyscribe-sdk/angular';