@molecule/app-address-display-angular

Feature · address-display · App (browser) · v1.1.2 · Apache-2.0

Formatted multi-line address card with edit/delete actions

npm install @molecule/app-address-display-angular

npm · Source on GitHub

How it works

@molecule/app-address-display-angular is a ready-made address-display feature for the app (browser) side. It composes the core interfaces it needs, so it works with whichever providers your app has bonded.

import { Component } from '@angular/core'
import { AddressDisplay } from '@molecule/app-address-display-angular'

@Component({
  selector: 'contact-card',
  standalone: true,
  imports: [AddressDisplay],
  template: `
    <div
      mol-address-display
      [address]="{
        line1: '123 Main St',
        city: 'Springfield',
        state: 'IL',
        postalCode: '62701',
        country: 'US',
      }"
      name="Jane Smith"
      phone="+1 555-867-5309"
    >
      <mol-edit-actions slot="actions" />
    </div>
  `,
})
export class ContactCard {}

Works with: @molecule/app-angular, @molecule/app-ui, @molecule/app-ui-angular

Reference

Angular formatted address display — the counterpart of @molecule/app-address-display-react: the same props and the same DOM for the same input.

Exports <AddressDisplay> — formatted multi-line (or inline) address with name, phone, leading icon, and action slots. Also exports the Address type.

Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit src/index.ts JSDoc, not this file.

Quick Start

import { Component } from '@angular/core'
import { AddressDisplay } from '@molecule/app-address-display-angular'

@Component({
  selector: 'contact-card',
  standalone: true,
  imports: [AddressDisplay],
  template: `
    <div
      mol-address-display
      [address]="{
        line1: '123 Main St',
        city: 'Springfield',
        state: 'IL',
        postalCode: '62701',
        country: 'US',
      }"
      name="Jane Smith"
      phone="+1 555-867-5309"
    >
      <mol-edit-actions slot="actions" />
    </div>
  `,
})
export class ContactCard {}

Type

feature

Installation

npm install @molecule/app-address-display-angular @angular/common @angular/core @angular/platform-browser @molecule/app-angular @molecule/app-ui @molecule/app-ui-angular

API

Interfaces

Address

Structured postal address with optional individual fields.

interface Address {
  /** First line — street + number. */
  line1?: string
  /** Second line — apartment, suite, unit. */
  line2?: string
  /** City. */
  city?: string
  /** State / province / region. */
  state?: string
  /** ZIP / postal code. */
  postalCode?: string
  /** Country. */
  country?: string
}

AddressDisplayProps

Props accepted by AddressDisplay — the same props @molecule/app-address-display-react accepts. Node props (name, leading, actions) are projected content in Angular (an input cannot carry a node), so they are typed unknown: pass them in the host template, not as values.

interface AddressDisplayProps {
  /** Address fields. */
  address: Address
  /** Optional name / label preceding the address, projected as `[slot=name]` content. */
  name?: unknown
  /** Optional phone number rendered under the address. */
  phone?: string
  /** Optional `<Icon>` / avatar leading slot, projected as `[slot=leading]` content. */
  leading?: unknown
  /** Optional right-side actions, projected as `[slot=actions]` content. */
  actions?: unknown
  /** Format as a single line instead of multi-line. */
  inline?: boolean
  /** Extra classes. */
  className?: string
}

Classes

AddressDisplay

AddressDisplay component.

Formatted multi-line address display with optional name, phone, leading slot, and right-side actions. Set inline to render all fields on a single line (e.g., in a table cell). The host IS the root <div> (div[mol-address-display]), matching React's root exactly. The name, leading and actions are projected content ([slot=name], [slot=leading], [slot=actions]); a string name input renders as text. Same props, same DOM as @molecule/app-address-display-react's AddressDisplay.

@Component({
  selector: 'div[mol-address-display]',
  standalone: true,
  inputs: ['address', 'name', 'phone', 'inline', 'className'],
  hostDirectives: [MolPlacement],
  host: {
    '[class]': 'classes()',
  },
  // prettier-ignore
  template: `<ng-content select="[slot=leading]" />
    <div [class]="innerClass()">
      <span #nameSpan [class]="nameClass()">@if (hasName) {<ng-container>{{ name }}</ng-container>}<ng-content select="[slot=name]" /></span>
      @if (inline) {<span>{{ inlineText() }}</span>} @else {<address [style.font-style]="'normal'">@for (line of lines(); track $index) {<span [style.display]="'block'">{{ line }}</span>}</address>}
      @if (hasPhone) {<a [attr.href]="'tel:' + phone" [class]="linkClass()">{{ phone }}</a>}
    </div>
    <ng-content select="[slot=actions]" />`,
})
export class AddressDisplay {
  /** Address fields. */
  address?: Address
  /** Optional name / label preceding the address: text, or `[slot=name]` content. */
  name?: unknown
  /** Optional phone number rendered under the address. */
  phone?: string
  /** Format as a single line instead of multi-line. */
  inline?: boolean
  /** Extra classes. */
  className?: string

  /** The name span (always in the body; detached while it has nothing to render). */
  @ViewChild('nameSpan', { static: true }) private nameSpan?: ElementRef<HTMLSpanElement>

  /**
   * Keeps the name span on the page only while it renders a text input or
   * projected `[slot=name]` content, re-decided whenever either changes (a
   * name taken away and given back included).
   */
  constructor() {
    usePlacement((hasContent) => {
      const span = this.nameSpan?.nativeElement
      setElementPresent(span, this.hasName || (span ? hasContent(span) : false))
    })
  }

  /**
   * Whether a text name input is present (React's truthiness: `''` renders
   * no name).
   * @returns True when the name input renders as text.
   */
  get hasName(): boolean {
    return this.name !== undefined && this.name !== null && this.name !== ''
  }

  /**
   * Whether the phone link renders (React's truthiness: `''` renders no
   * link).
   * @returns True when the phone shows.
   */
  get hasPhone(): boolean {
    return this.phone !== undefined && this.phone !== null && this.phone !== ''
  }

  /**
   * The current class map.
   * @returns The UIClassMap.
   */
  cm(): UIClassMap {
    return getClassMap()
  }

  /**
   * Computes the root class list.
   * @returns The class string.
   */
  classes(): string {
    return this.cm().cn(this.cm().flex({ align: 'start', gap: 'sm' }), this.className)
  }

  /**
   * The body column's class.
   * @returns The class string.
   */
  innerClass(): string {
    return this.cm().cn(this.cm().flex1, this.cm().stack(1), this.cm().textSize('sm'))
  }

  /**
   * The name span's class (React's `cm.fontWeight('semibold')`, through `cn`
   * so every binding carries a plain string).
   * @returns The class string.
   */
  nameClass(): string {
    return this.cm().cn(this.cm().fontWeight('semibold'))
  }

  /**
   * The phone link's class (React's `cm.link`, through `cn` so every binding
   * carries a plain string).
   * @returns The class string.
   */
  linkClass(): string {
    return this.cm().cn(this.cm().link)
  }

  /**
   * The address's display lines, from the current `address` input.
   * @returns The non-empty display lines, in postal order.
   */
  lines(): string[] {
    return joinAddress(this.address ?? {})
  }

  /**
   * The inline body: every field joined on one line (React's
   * `lines.join(', ')`).
   * @returns The single-line text.
   */
  inlineText(): string {
    return this.lines().join(', ')
  }
}

Injection Notes

Requirements

Peer dependencies:

  • @angular/common ^22.0.0
  • @angular/core ^22.0.0
  • @angular/platform-browser ^22.0.0
  • @molecule/app-angular ^3.13.0 || ^4.0.0
  • @molecule/app-ui ^1.0.1
  • @molecule/app-ui-angular ^1.1.0

Runtime Dependencies

  • @angular/common

  • @angular/core

  • @angular/platform-browser

  • @molecule/app-angular

  • @molecule/app-ui

  • @molecule/app-ui-angular

  • Requires a bonded ClassMap — rendering throws otherwise. No i18n or router dependency.

  • Node props are projected content: name, leading and actions are selected by [slot=name] / [slot=leading] / [slot=actions]; a string name input renders as text instead.