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
This commit is contained in:
Jeffrey Bosch
2017-11-02 04:30:45 +01:00
committed by Andrew Seguin
parent eaa4a36668
commit c8df2c16d7
2 changed files with 16 additions and 3 deletions
+14 -1
View File
@@ -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
};
+2 -2
View File
@@ -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 {}