Angular

Integrate DotPassport widgets with Angular.

Installation

npm install @dotpassport/sdk

Basic Component

// dotpassport-widget.component.ts
import {
  Component,
  Input,
  OnInit,
  OnDestroy,
  OnChanges,
  SimpleChanges,
  ElementRef,
  ViewChild
} from '@angular/core';
import { createWidget, type WidgetConfig } from '@dotpassport/sdk';
import { environment } from '../environments/environment';

@Component({
  selector: 'app-dotpassport-widget',
  template: '<div #container></div>',
  standalone: true
})
export class DotPassportWidgetComponent implements OnInit, OnDestroy, OnChanges {
  @Input() address!: string;
  @Input() type: WidgetConfig['type'] = 'reputation';
  @Input() theme: 'light' | 'dark' | 'auto' = 'light';

  @ViewChild('container', { static: true }) container!: ElementRef<HTMLDivElement>;

  private widget: ReturnType<typeof createWidget> | null = null;

  ngOnInit(): void {
    this.widget = createWidget({
      apiKey: environment.dotpassportApiKey,
      address: this.address,
      type: this.type,
      theme: this.theme
    });
    this.widget.mount(this.container.nativeElement);
  }

  ngOnChanges(changes: SimpleChanges): void {
    if (this.widget) {
      if (changes['address'] || changes['theme']) {
        this.widget.update({
          address: this.address,
          theme: this.theme
        });
      }
    }
  }

  ngOnDestroy(): void {
    this.widget?.destroy();
  }

  refresh(): void {
    this.widget?.refresh();
  }
}

Usage


Reputation Widget Component

Usage


Service-Based Approach

Usage in Component


Multiple Widgets Dashboard


Environment Configuration


Reactive Forms Integration


Last updated