Options
All
  • Public
  • Public/Protected
  • All
Menu

Class NameOf

Helper to get property names of an object. Useful when you need the property of an object as string. For example to map a data source to a table. It shows you the available properties and typescript is going to validate if the property really exists.

Hierarchy

  • NameOf

Index

Methods

Methods

Static property

  • property<T>(propertyName: keyof T): string
  • Returns the propertyName as string.

    example

    Set the text and value field to a drop-down component.

    export class ProductModel {
      public id: number;
      public name: string;
    }
    
    @Component({
      selector: 'app-product',
      templateUrl: './product.component.html',
      styleUrls: ['./product.component.css']
    })
    export class ProductComponent implements AfterViewInit {
      @ViewChild(DropdownComponent, {static: false})
      private dropdown: DropdownComponent;
    
      public ngAfterViewInit() {
        dropdown.textField = NameOf.property<ProductModel>('name');
        dropdown.valueField = NameOf.property<ProductModel>('id');
      }
    }

    Type parameters

    • T

    Parameters

    • propertyName: keyof T

      A property name of the T object.

    Returns string

Generated using TypeDoc