Skip to content

Commit

Permalink
fix(MatPaginatorIntl): Provide a provider if exists. (#7895)
Browse files Browse the repository at this point in the history
* fix(MatPaginatorIntl): Provide a provider if exists.

If there is already a MatPaginatorIntl provider that one
If not create a new instance.

Closes #7344

* style(paginator): Changed arguments, removed spacing

* style(paginator): Changed argument name.
  • Loading branch information
Jefiozie authored and andrewseguin committed Nov 2, 2017
1 parent ee4915c commit 9a05ecd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
15 changes: 14 additions & 1 deletion src/lib/paginator/paginator-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';

/**
Expand Down Expand Up @@ -46,3 +46,16 @@ export class MatPaginatorIntl {
return `${startIndex + 1} - ${endIndex} of ${length}`;
}
}

/** @docs-private */
export function MAT_PAGINATOR_INTL_PROVIDER_FACTORY(parentIntl: MatPaginatorIntl) {
return parentIntl || new MatPaginatorIntl();
}

/** @docs-private */
export const MAT_PAGINATOR_INTL_PROVIDER = {
// If there is already an MatPaginatorIntl available, use that. Otherwise, provide a new one.
provide: MatPaginatorIntl,
deps: [[new Optional(), new SkipSelf(), MatPaginatorIntl]],
useFactory: MAT_PAGINATOR_INTL_PROVIDER_FACTORY
};
4 changes: 2 additions & 2 deletions src/lib/paginator/paginator-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {MatButtonModule} from '@angular/material/button';
import {MatSelectModule} from '@angular/material/select';
import {MatTooltipModule} from '@angular/material/tooltip';
import {MatPaginator} from './paginator';
import {MatPaginatorIntl} from './paginator-intl';
import {MAT_PAGINATOR_INTL_PROVIDER} from './paginator-intl';


@NgModule({
Expand All @@ -24,6 +24,6 @@ import {MatPaginatorIntl} from './paginator-intl';
],
exports: [MatPaginator],
declarations: [MatPaginator],
providers: [MatPaginatorIntl],
providers: [MAT_PAGINATOR_INTL_PROVIDER],
})
export class MatPaginatorModule {}

0 comments on commit 9a05ecd

Please sign in to comment.