Skip to content

Commit c8df2c1

Browse files
Jefiozieandrewseguin
authored andcommitted
feat(sort): if provider exists provider one, otherwise new one (#7988)
* feat(sort): if provider exists provider one, otherwise new one * fix(sort): added provider in module
1 parent eaa4a36 commit c8df2c1

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/lib/sort/sort-header-intl.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {Injectable} from '@angular/core';
9+
import {Injectable, SkipSelf, Optional} from '@angular/core';
1010
import {Subject} from 'rxjs/Subject';
1111
import {SortDirection} from './sort-direction';
1212

@@ -32,3 +32,16 @@ export class MatSortHeaderIntl {
3232
return `Sorted by ${id} ${direction == 'asc' ? 'ascending' : 'descending'}`;
3333
}
3434
}
35+
/** @docs-private */
36+
export function MAT_SORT_HEADER_INTL_PROVIDER_FACTORY(parentIntl: MatSortHeaderIntl) {
37+
return parentIntl || new MatSortHeaderIntl();
38+
}
39+
40+
/** @docs-private */
41+
export const MAT_SORT_HEADER_INTL_PROVIDER = {
42+
// If there is already an MatSortHeaderIntl available, use that. Otherwise, provide a new one.
43+
provide: MatSortHeaderIntl,
44+
deps: [[new Optional(), new SkipSelf(), MatSortHeaderIntl]],
45+
useFactory: MAT_SORT_HEADER_INTL_PROVIDER_FACTORY
46+
};
47+

src/lib/sort/sort-module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
import {NgModule} from '@angular/core';
1010
import {MatSortHeader} from './sort-header';
1111
import {MatSort} from './sort';
12-
import {MatSortHeaderIntl} from './sort-header-intl';
12+
import {MAT_SORT_HEADER_INTL_PROVIDER} from './sort-header-intl';
1313
import {CommonModule} from '@angular/common';
1414

1515

1616
@NgModule({
1717
imports: [CommonModule],
1818
exports: [MatSort, MatSortHeader],
1919
declarations: [MatSort, MatSortHeader],
20-
providers: [MatSortHeaderIntl]
20+
providers: [MAT_SORT_HEADER_INTL_PROVIDER]
2121
})
2222
export class MatSortModule {}

0 commit comments

Comments
 (0)