From f6f2ef27aae431babd338856a196ac1e8056f48a Mon Sep 17 00:00:00 2001 From: Jefiozie Date: Tue, 24 Oct 2017 08:08:57 +0200 Subject: [PATCH 1/2] feat(sort): if provider exists provider one, otherwise new one --- src/lib/sort/sort-header-intl.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/lib/sort/sort-header-intl.ts b/src/lib/sort/sort-header-intl.ts index 38be337a1373..8dee33142340 100644 --- a/src/lib/sort/sort-header-intl.ts +++ b/src/lib/sort/sort-header-intl.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {Injectable} from '@angular/core'; +import {Injectable, SkipSelf, Optional} from '@angular/core'; import {Subject} from 'rxjs/Subject'; import {SortDirection} from './sort-direction'; @@ -32,3 +32,16 @@ export class MatSortHeaderIntl { return `Sorted by ${id} ${direction == 'asc' ? 'ascending' : 'descending'}`; } } +/** @docs-private */ +export function MAT_SORT_HEADER_INTL_PROVIDER_FACTORY(parentIntl: MatSortHeaderIntl) { + return parentIntl || new MatSortHeaderIntl(); +} + +/** @docs-private */ +export const MAT_SORT_HEADER_INTL_PROVIDER = { + // If there is already an MatSortHeaderIntl available, use that. Otherwise, provide a new one. + provide: MatSortHeaderIntl, + deps: [[new Optional(), new SkipSelf(), MatSortHeaderIntl]], + useFactory: MAT_SORT_HEADER_INTL_PROVIDER_FACTORY +}; + From 3d4a49eb41efc7c49ca23bce63e88149748b51d3 Mon Sep 17 00:00:00 2001 From: Jefiozie Date: Tue, 24 Oct 2017 21:59:06 +0200 Subject: [PATCH 2/2] fix(sort): added provider in module --- src/lib/sort/sort-module.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/sort/sort-module.ts b/src/lib/sort/sort-module.ts index 0d3941a33a9b..dc8151dda729 100644 --- a/src/lib/sort/sort-module.ts +++ b/src/lib/sort/sort-module.ts @@ -9,7 +9,7 @@ import {NgModule} from '@angular/core'; import {MatSortHeader} from './sort-header'; import {MatSort} from './sort'; -import {MatSortHeaderIntl} from './sort-header-intl'; +import {MAT_SORT_HEADER_INTL_PROVIDER} from './sort-header-intl'; import {CommonModule} from '@angular/common'; @@ -17,6 +17,6 @@ import {CommonModule} from '@angular/common'; imports: [CommonModule], exports: [MatSort, MatSortHeader], declarations: [MatSort, MatSortHeader], - providers: [MatSortHeaderIntl] + providers: [MAT_SORT_HEADER_INTL_PROVIDER] }) export class MatSortModule {}