Link
Link

Reputation: 1711

Using string enum value in HTML component in angular

Imagine the following string enum, which is defined in a component.ts:

export enum SortType {
 Date = 'date',
}

I want to use the value of the enum in the corresponding HTML-component: <th mat-sort-header=??? >

Something like that: <th mat-sort-header='SortType.Date' >.

Upvotes: 1

Views: 298

Answers (2)

Ashish Ranjan
Ashish Ranjan

Reputation: 12960

Assign the value of imported Enum in a class property.

import { SortType } from '.....path'

@component({data})
export class YourComponent  {
  sortEnum = SortType;
}

Use in your HTML

<th mat-sort-header="{{sortEnum.Date}}" >.

Upvotes: 2

Arun Mohan
Arun Mohan

Reputation: 1227

In ts create a class property as public sortEnum=SortType and access in html

public sortEnum=SortType

Upvotes: 1

Related Questions