1

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' >.

2 Answers 2

2

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}}" >.
Sign up to request clarification or add additional context in comments.

2 Comments

That brings me the exact same string. I have a console.log(sort.active) in the sort-function of mat-sort (matSort (matSortChange)="sort($event)). In this case it shows me 'sortEnum.Date' instead of 'date'
@Link I am sorry, misssed the interpolation
1

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

public sortEnum=SortType

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.