Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use angular material api services?

I am a beginner to the angular world, I was using the angular material's "Sort header" component, and on the API tab (https://material.angular.io/components/sort/api) there is something called services, and I want to use them, But I don't get it how do to use it.

For example:

On the API tab of "Sort header" or (https://material.angular.io/components/sort/api)

I want to use the service "MatSortHeaderIntl", it has some properties such as - sortDescriptionLabel

So please tell me how to use "sortDescriptionLabel" property of "MatSortHeaderIntl" service.

Thanks.

like image 658
vivek gupta Avatar asked Sep 16 '26 21:09

vivek gupta


1 Answers

You need to import, and provide it to your module

import {MatSortHeaderIntl} from '@angular/material';

@NgModule({
  imports: [
       ...
  ],
  entryComponents: [..],
  declarations: [...],
  bootstrap: [...],
  providers: [MatSortHeaderIntl]
})
export class AppModule {}

Then in whatever component you want to use it, instantiate it

constructor( private matSortService: MatSortHeaderIntl) {}

and you can call it by scope

this.matSortService.<method>

I setup an example of Integrated MatSortHeaderIntl Service

like image 198
Iancovici Avatar answered Sep 18 '26 11:09

Iancovici