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:
Jeffrey Bosch
2017-11-02 04:36:26 +01:00
committed by Andrew Seguin
parent ee4915cfca
commit 9a05ecdb63
2 changed files with 16 additions and 3 deletions
+14 -1
View File
@@ -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
};
+2 -2
View File
@@ -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 {}