Skip to content

feat(material): use scoped injectables #10507

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/cdk/layout/breakpoints-observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ interface Query {
}

/** Utility for checking the matching state of @media queries. */
@Injectable()
@Injectable({providedIn: 'root'})
export class BreakpointObserver implements OnDestroy {
/** A map of all media queries currently being listened for. */
private _queries: Map<string, Query> = new Map();
Expand Down
9 changes: 2 additions & 7 deletions src/cdk/layout/layout-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {NgModule} from '@angular/core';
import {PlatformModule} from '@angular/cdk/platform';
import {BreakpointObserver} from './breakpoints-observer';
import {MediaMatcher} from './media-matcher';

@NgModule({
providers: [BreakpointObserver, MediaMatcher],
imports: [PlatformModule],
})

@NgModule()
export class LayoutModule {}
2 changes: 1 addition & 1 deletion src/cdk/layout/media-matcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {Platform} from '@angular/cdk/platform';
const styleElementForWebkitCompatibility: Map<string, HTMLStyleElement> = new Map();

/** A utility for calling matchMedia queries. */
@Injectable()
@Injectable({providedIn: 'root'})
export class MediaMatcher {
/** The internal matchMedia method to return back a MediaQueryList like object. */
private _matchMedia: (query: string) => MediaQueryList;
Expand Down
7 changes: 1 addition & 6 deletions src/lib/autocomplete/autocomplete-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,14 @@ import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {OverlayModule} from '@angular/cdk/overlay';
import {MatOptionModule, MatCommonModule} from '@angular/material/core';
import {MatAutocomplete, MAT_AUTOCOMPLETE_DEFAULT_OPTIONS} from './autocomplete';
import {MatAutocomplete} from './autocomplete';
import {
MatAutocompleteTrigger,
MAT_AUTOCOMPLETE_SCROLL_STRATEGY_PROVIDER,
} from './autocomplete-trigger';

@NgModule({
imports: [MatOptionModule, OverlayModule, MatCommonModule, CommonModule],
exports: [MatAutocomplete, MatOptionModule, MatAutocompleteTrigger, MatCommonModule],
declarations: [MatAutocomplete, MatAutocompleteTrigger],
providers: [
MAT_AUTOCOMPLETE_SCROLL_STRATEGY_PROVIDER,
{provide: MAT_AUTOCOMPLETE_DEFAULT_OPTIONS, useValue: false}
],
})
export class MatAutocompleteModule {}
44 changes: 19 additions & 25 deletions src/lib/autocomplete/autocomplete-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,25 @@
* found in the LICENSE file at https://angular.io/license
*/
import {Directionality} from '@angular/cdk/bidi';
import {DOWN_ARROW, ENTER, ESCAPE, UP_ARROW, TAB} from '@angular/cdk/keycodes';
import {DOWN_ARROW, ENTER, ESCAPE, TAB, UP_ARROW} from '@angular/cdk/keycodes';
import {
FlexibleConnectedPositionStrategy,
Overlay,
OverlayRef,
OverlayConfig,
OverlayRef,
PositionStrategy,
ScrollStrategy,
} from '@angular/cdk/overlay';
import {TemplatePortal} from '@angular/cdk/portal';
import {filter} from 'rxjs/operators/filter';
import {take} from 'rxjs/operators/take';
import {switchMap} from 'rxjs/operators/switchMap';
import {tap} from 'rxjs/operators/tap';
import {delay} from 'rxjs/operators/delay';
import {DOCUMENT} from '@angular/common';
import {
ChangeDetectorRef,
Directive,
ElementRef,
forwardRef,
Host,
Inject,
inject,
InjectionToken,
Input,
NgZone,
Expand All @@ -37,19 +34,23 @@ import {
} from '@angular/core';
import {ControlValueAccessor, NG_VALUE_ACCESSOR} from '@angular/forms';
import {
_countGroupLabelsBeforeOption,
_getOptionScrollPosition,
MatOption,
MatOptionSelectionChange,
_getOptionScrollPosition,
_countGroupLabelsBeforeOption,
} from '@angular/material/core';
import {MatFormField} from '@angular/material/form-field';
import {DOCUMENT} from '@angular/common';
import {Observable} from 'rxjs/Observable';
import {Subject} from 'rxjs/Subject';
import {defer} from 'rxjs/observable/defer';
import {fromEvent} from 'rxjs/observable/fromEvent';
import {merge} from 'rxjs/observable/merge';
import {of as observableOf} from 'rxjs/observable/of';
import {delay} from 'rxjs/operators/delay';
import {filter} from 'rxjs/operators/filter';
import {switchMap} from 'rxjs/operators/switchMap';
import {take} from 'rxjs/operators/take';
import {tap} from 'rxjs/operators/tap';
import {Subject} from 'rxjs/Subject';
import {Subscription} from 'rxjs/Subscription';
import {MatAutocomplete} from './autocomplete';

Expand All @@ -68,20 +69,13 @@ export const AUTOCOMPLETE_PANEL_HEIGHT = 256;

/** Injection token that determines the scroll handling while the autocomplete panel is open. */
export const MAT_AUTOCOMPLETE_SCROLL_STRATEGY =
new InjectionToken<() => ScrollStrategy>('mat-autocomplete-scroll-strategy');

/** @docs-private */
export function MAT_AUTOCOMPLETE_SCROLL_STRATEGY_PROVIDER_FACTORY(overlay: Overlay):
() => ScrollStrategy {
return () => overlay.scrollStrategies.reposition();
}

/** @docs-private */
export const MAT_AUTOCOMPLETE_SCROLL_STRATEGY_PROVIDER = {
provide: MAT_AUTOCOMPLETE_SCROLL_STRATEGY,
deps: [Overlay],
useFactory: MAT_AUTOCOMPLETE_SCROLL_STRATEGY_PROVIDER_FACTORY,
};
new InjectionToken<() => ScrollStrategy>('mat-autocomplete-scroll-strategy', {
providedIn: 'root',
factory: () => {
const overlay = inject(Overlay);
return () => overlay.scrollStrategies.reposition();
}
});

/**
* Provider that allows the autocomplete to register as a ControlValueAccessor.
Expand Down
5 changes: 4 additions & 1 deletion src/lib/autocomplete/autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ export interface MatAutocompleteDefaultOptions {

/** Injection token to be used to override the default options for `mat-autocomplete`. */
export const MAT_AUTOCOMPLETE_DEFAULT_OPTIONS =
new InjectionToken<MatAutocompleteDefaultOptions>('mat-autocomplete-default-options');
new InjectionToken<MatAutocompleteDefaultOptions>('mat-autocomplete-default-options', {
providedIn: 'root',
factory: () => ({autoActiveFirstOption: false}),
});


@Component({
Expand Down
14 changes: 3 additions & 11 deletions src/lib/badge/badge-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,12 @@

import {NgModule} from '@angular/core';
import {MatCommonModule} from '@angular/material/core';
import {A11yModule} from '@angular/cdk/a11y';
import {MatBadge} from './badge';


@NgModule({
imports: [
MatCommonModule,
A11yModule,
],
exports: [
MatBadge,
],
declarations: [
MatBadge,
],
imports: [MatCommonModule],
exports: [MatBadge],
declarations: [MatBadge],
})
export class MatBadgeModule {}
12 changes: 4 additions & 8 deletions src/lib/bottom-sheet/bottom-sheet-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,21 @@
* found in the LICENSE file at https://angular.io/license
*/

import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {MatCommonModule} from '@angular/material/core';
import {A11yModule} from '@angular/cdk/a11y';
import {OverlayModule} from '@angular/cdk/overlay';
import {PortalModule} from '@angular/cdk/portal';
import {LayoutModule} from '@angular/cdk/layout';
import {MatBottomSheetContainer} from './bottom-sheet-container';
import {CommonModule} from '@angular/common';
import {NgModule} from '@angular/core';
import {MatCommonModule} from '@angular/material/core';
import {MatBottomSheet} from './bottom-sheet';
import {MatBottomSheetContainer} from './bottom-sheet-container';


@NgModule({
imports: [
A11yModule,
CommonModule,
OverlayModule,
MatCommonModule,
PortalModule,
LayoutModule,
],
exports: [MatBottomSheetContainer, MatCommonModule],
declarations: [MatBottomSheetContainer],
Expand Down
3 changes: 1 addition & 2 deletions src/lib/button-toggle/button-toggle-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
* found in the LICENSE file at https://angular.io/license
*/

import {A11yModule} from '@angular/cdk/a11y';
import {NgModule} from '@angular/core';
import {MatCommonModule, MatRippleModule} from '@angular/material/core';
import {MatButtonToggle, MatButtonToggleGroup} from './button-toggle';


@NgModule({
imports: [MatCommonModule, MatRippleModule, A11yModule],
imports: [MatCommonModule, MatRippleModule],
exports: [MatCommonModule, MatButtonToggleGroup, MatButtonToggle],
declarations: [MatButtonToggleGroup, MatButtonToggle],
})
Expand Down
9 changes: 2 additions & 7 deletions src/lib/button/button-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,17 @@
* found in the LICENSE file at https://angular.io/license
*/

import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {NgModule} from '@angular/core';
import {MatCommonModule, MatRippleModule} from '@angular/material/core';
import {A11yModule} from '@angular/cdk/a11y';
import {
MatAnchor,
MatButton,
} from './button';
import {MatAnchor, MatButton} from './button';


@NgModule({
imports: [
CommonModule,
MatRippleModule,
MatCommonModule,
A11yModule,
],
exports: [
MatButton,
Expand Down
18 changes: 9 additions & 9 deletions src/lib/card/card-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ import {NgModule} from '@angular/core';
import {MatCommonModule} from '@angular/material/core';
import {
MatCard,
MatCardHeader,
MatCardTitleGroup,
MatCardContent,
MatCardTitle,
MatCardSubtitle,
MatCardActions,
MatCardAvatar,
MatCardContent,
MatCardFooter,
MatCardSmImage,
MatCardMdImage,
MatCardLgImage,
MatCardHeader,
MatCardImage,
MatCardLgImage,
MatCardMdImage,
MatCardSmImage,
MatCardSubtitle,
MatCardTitle,
MatCardTitleGroup,
MatCardXlImage,
MatCardAvatar,
} from './card';


Expand Down
10 changes: 5 additions & 5 deletions src/lib/checkbox/checkbox-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
* found in the LICENSE file at https://angular.io/license
*/

import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {ObserversModule} from '@angular/cdk/observers';
import {MatRippleModule, MatCommonModule} from '@angular/material/core';
import {CommonModule} from '@angular/common';
import {NgModule} from '@angular/core';
import {MatCommonModule, MatRippleModule} from '@angular/material/core';
import {MatCheckbox} from './checkbox';
import {MatCheckboxRequiredValidator} from './checkbox-required-validator';
import {A11yModule} from '@angular/cdk/a11y';


@NgModule({
imports: [CommonModule, MatRippleModule, MatCommonModule, ObserversModule, A11yModule],
imports: [CommonModule, MatRippleModule, MatCommonModule, ObserversModule],
exports: [MatCheckbox, MatCheckboxRequiredValidator, MatCommonModule],
declarations: [MatCheckbox, MatCheckboxRequiredValidator],
})
Expand Down
6 changes: 2 additions & 4 deletions src/lib/chips/chips-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
* found in the LICENSE file at https://angular.io/license
*/

import {PlatformModule} from '@angular/cdk/platform';
import {ENTER} from '@angular/cdk/keycodes';
import {NgModule} from '@angular/core';
import {ErrorStateMatcher} from '@angular/material/core';
import {MatChip, MatChipAvatar, MatChipRemove, MatChipTrailingIcon} from './chip';
import {MAT_CHIPS_DEFAULT_OPTIONS, MatChipsDefaultOptions} from './chip-default-options';
import {MatChipInput} from './chip-input';
import {MatChipList} from './chip-list';
import {MAT_CHIPS_DEFAULT_OPTIONS, MatChipsDefaultOptions} from './chip-default-options';
import {ENTER} from '@angular/cdk/keycodes';

const CHIP_DECLARATIONS = [
MatChipList,
Expand All @@ -25,7 +24,6 @@ const CHIP_DECLARATIONS = [
];

@NgModule({
imports: [PlatformModule],
exports: CHIP_DECLARATIONS,
declarations: CHIP_DECLARATIONS,
providers: [
Expand Down
8 changes: 4 additions & 4 deletions src/lib/core/common-behaviors/common-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import {BidiModule} from '@angular/cdk/bidi';


/** Injection token that configures whether the Material sanity checks are enabled. */
export const MATERIAL_SANITY_CHECKS = new InjectionToken<boolean>('mat-sanity-checks');
export const MATERIAL_SANITY_CHECKS = new InjectionToken<boolean>('mat-sanity-checks', {
providedIn: 'root',
factory: () => true,
});


/**
Expand All @@ -23,9 +26,6 @@ export const MATERIAL_SANITY_CHECKS = new InjectionToken<boolean>('mat-sanity-ch
@NgModule({
imports: [BidiModule],
exports: [BidiModule],
providers: [{
provide: MATERIAL_SANITY_CHECKS, useValue: true,
}],
})
export class MatCommonModule {
/** Whether we've done the global sanity checks (e.g. a theme is loaded, there is a doctype). */
Expand Down
10 changes: 5 additions & 5 deletions src/lib/core/datetime/date-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
* found in the LICENSE file at https://angular.io/license
*/

import {InjectionToken, LOCALE_ID} from '@angular/core';
import {inject, InjectionToken, LOCALE_ID} from '@angular/core';
import {Observable} from 'rxjs/Observable';
import {Subject} from 'rxjs/Subject';


/** InjectionToken for datepicker that can be used to override default locale code. */
export const MAT_DATE_LOCALE = new InjectionToken<string>('MAT_DATE_LOCALE');

/** Provider for MAT_DATE_LOCALE injection token. */
export const MAT_DATE_LOCALE_PROVIDER = {provide: MAT_DATE_LOCALE, useExisting: LOCALE_ID};
export const MAT_DATE_LOCALE = new InjectionToken<string>('MAT_DATE_LOCALE', {
providedIn: 'root',
factory: () => inject(LOCALE_ID)
});

/** Adapts type `D` to be usable as a date by cdk-based components that work with dates. */
export abstract class DateAdapter<D> {
Expand Down
Loading