Skip to content

Commit

Permalink
feat(sort): if provider exists provider one, otherwise new one (#7988)
Browse files Browse the repository at this point in the history
* feat(sort): if provider exists provider one, otherwise new one

* fix(sort): added provider in module
  • Loading branch information
Jefiozie authored and andrewseguin committed Nov 2, 2017
1 parent eaa4a36 commit c8df2c1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
15 changes: 14 additions & 1 deletion src/lib/sort/sort-header-intl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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
};

4 changes: 2 additions & 2 deletions src/lib/sort/sort-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
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';


@NgModule({
imports: [CommonModule],
exports: [MatSort, MatSortHeader],
declarations: [MatSort, MatSortHeader],
providers: [MatSortHeaderIntl]
providers: [MAT_SORT_HEADER_INTL_PROVIDER]
})
export class MatSortModule {}

0 comments on commit c8df2c1

Please sign in to comment.