mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
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:
committed by
Andrew Seguin
parent
eaa4a36668
commit
c8df2c16d7
@@ -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
|
||||
};
|
||||
|
||||
|
||||
@@ -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 {}
|
||||
|
||||
Reference in New Issue
Block a user