Skip to content

Commit 9a05ecd

Browse files
Jefiozieandrewseguin
authored andcommitted
fix(MatPaginatorIntl): Provide a provider if exists. (#7895)
* 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.
1 parent ee4915c commit 9a05ecd

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/lib/paginator/paginator-intl.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {Injectable} from '@angular/core';
9+
import {Injectable, SkipSelf, Optional } from '@angular/core';
1010
import {Subject} from 'rxjs/Subject';
1111

1212
/**
@@ -46,3 +46,16 @@ export class MatPaginatorIntl {
4646
return `${startIndex + 1} - ${endIndex} of ${length}`;
4747
}
4848
}
49+
50+
/** @docs-private */
51+
export function MAT_PAGINATOR_INTL_PROVIDER_FACTORY(parentIntl: MatPaginatorIntl) {
52+
return parentIntl || new MatPaginatorIntl();
53+
}
54+
55+
/** @docs-private */
56+
export const MAT_PAGINATOR_INTL_PROVIDER = {
57+
// If there is already an MatPaginatorIntl available, use that. Otherwise, provide a new one.
58+
provide: MatPaginatorIntl,
59+
deps: [[new Optional(), new SkipSelf(), MatPaginatorIntl]],
60+
useFactory: MAT_PAGINATOR_INTL_PROVIDER_FACTORY
61+
};

src/lib/paginator/paginator-module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {MatButtonModule} from '@angular/material/button';
1212
import {MatSelectModule} from '@angular/material/select';
1313
import {MatTooltipModule} from '@angular/material/tooltip';
1414
import {MatPaginator} from './paginator';
15-
import {MatPaginatorIntl} from './paginator-intl';
15+
import {MAT_PAGINATOR_INTL_PROVIDER} from './paginator-intl';
1616

1717

1818
@NgModule({
@@ -24,6 +24,6 @@ import {MatPaginatorIntl} from './paginator-intl';
2424
],
2525
exports: [MatPaginator],
2626
declarations: [MatPaginator],
27-
providers: [MatPaginatorIntl],
27+
providers: [MAT_PAGINATOR_INTL_PROVIDER],
2828
})
2929
export class MatPaginatorModule {}

0 commit comments

Comments
 (0)