
Product
Rust Support Now in Beta
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
This project was inspired by the amazing work of Dafnik/ngx-trpc
and @analogjs/trpc
. It builds upon the same principles of type-safe API communication and seamless Angular integration, with added features such as WebSocket subscriptions.
Since the REQUEST token is reintroduced in v19, this library is compatible only with that version.
This project is a work in progress. Features and APIs may change as development continues. Use at your own risk, and expect frequent updates. Contributions and feedback are always welcome!
To start using the Angular tRPC Client in your project, install it via npm:
npm i ngx-trpc
First, define a global injection token using the AppRouter
type from your tRPC backend. This will allow you to inject your tRPC client throughout your Angular app.
import { createTrpcInjectionToken } from 'ngx-trpc';
export const TRPC = createTrpcInjectionToken<AppRouter>();
Next, provide the tRPC client and httpClient in your app.config.ts
file. (example)
import { provideTrpc } from 'ngx-trpc';
provideHttpClient(withFetch())
provideTrpc(TRPC, { options })
You can now use the TRPC injection token to call tRPC queries as RxJS observables inside your components. Here's an example of how to call the hello query.
import { TRPC } from '../path/to/injection-token';
@Component({
selector: 'app-demo',
template: '{{ demoQuery$ | async | json }}',
})
export class DemoComponent {
readonly trpc = inject(TRPC);
readonly demoQuery$ = this.trpc.hello.query();
}
Headers are not forwarded when performing requests in ssr.
Add this provider to your app.config.server.ts
file to fix this issue:
provideServerRoutesConfig([{path: '**', renderMode: RenderMode.Server}])
FAQs
Angular integration for tRPC
We found that ngx-trpc demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.