mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
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.
This commit is contained in:
committed by
Andrew Seguin
parent
ee4915cfca
commit
9a05ecdb63
@@ -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';
|
||||
|
||||
/**
|
||||
@@ -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
|
||||
};
|
||||
|
||||
@@ -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({
|
||||
@@ -24,6 +24,6 @@ import {MatPaginatorIntl} from './paginator-intl';
|
||||
],
|
||||
exports: [MatPaginator],
|
||||
declarations: [MatPaginator],
|
||||
providers: [MatPaginatorIntl],
|
||||
providers: [MAT_PAGINATOR_INTL_PROVIDER],
|
||||
})
|
||||
export class MatPaginatorModule {}
|
||||
|
||||
Reference in New Issue
Block a user