-
Notifications
You must be signed in to change notification settings - Fork 4
fix(components): scroll strategy tokens throw NullInjectorError outside their NgModule (#DS-3522) #1888
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
fix(components): scroll strategy tokens throw NullInjectorError outside their NgModule (#DS-3522) #1888
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,21 @@ | ||
| import { inject } from '@angular/core'; | ||
| import { DateAdapter } from '@koobiq/components/core'; | ||
|
|
||
| /** @docs-private */ | ||
| export function createMissingDateImplError(provider: string) { | ||
| return Error( | ||
| `KbqDatepicker: No provider found for ${provider}. You must import one of the existing ` + | ||
| `modules at your application root or provide a custom implementation or use exists ones.` | ||
| ); | ||
| } | ||
|
|
||
| /** Injects `DateAdapter`, naming the missing provider instead of letting DI throw a bare `NullInjectorError`. */ | ||
| export function injectRequiredDateAdapter<D>(): DateAdapter<D> { | ||
| const adapter = inject<DateAdapter<D>>(DateAdapter, { optional: true }); | ||
|
|
||
| if (!adapter) { | ||
| throw createMissingDateImplError('DateAdapter'); | ||
| } | ||
|
|
||
| return adapter; | ||
| } |
79 changes: 79 additions & 0 deletions
79
packages/components/datepicker/datepicker-in-modal.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import { OverlayContainer } from '@angular/cdk/overlay'; | ||
| import { Component, inject } from '@angular/core'; | ||
| import { fakeAsync, flush, TestBed, tick } from '@angular/core/testing'; | ||
| import { FormsModule } from '@angular/forms'; | ||
| import { NoopAnimationsModule } from '@angular/platform-browser/animations'; | ||
| import { KBQ_LUXON_DATE_FORMATS, KbqLuxonDateModule } from '@koobiq/angular-luxon-adapter/adapter'; | ||
| import { KBQ_DATE_FORMATS } from '@koobiq/components/core'; | ||
| import { KbqFormFieldModule } from '@koobiq/components/form-field'; | ||
| import { KbqModalModule, KbqModalService } from '@koobiq/components/modal'; | ||
| import { KbqDatepickerModule } from './index'; | ||
|
|
||
| /** Reproduces the reported scenario: a datepicker living inside a `KbqModalService`-created component. */ | ||
| @Component({ | ||
| selector: 'modal-content-with-datepicker', | ||
| imports: [FormsModule, KbqDatepickerModule, KbqFormFieldModule], | ||
| template: ` | ||
| <kbq-form-field> | ||
| <input [kbqDatepicker]="picker" [ngModel]="null" /> | ||
| <kbq-datepicker-toggle-icon kbqSuffix [for]="picker" /> | ||
| <kbq-datepicker #picker /> | ||
| </kbq-form-field> | ||
| ` | ||
| }) | ||
| class ModalContentWithDatepicker {} | ||
|
|
||
| @Component({ | ||
| selector: 'modal-host', | ||
| imports: [KbqModalModule], | ||
| template: '' | ||
| }) | ||
| class ModalHost { | ||
| readonly modalService = inject(KbqModalService); | ||
|
|
||
| open() { | ||
| return this.modalService.open({ kbqComponent: ModalContentWithDatepicker }); | ||
| } | ||
| } | ||
|
|
||
| describe('datepicker inside a modal', () => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Достаточно ли просто добавить в datepicker.spec.ts, чтобы не создавать новый файл? |
||
| let overlayContainer: OverlayContainer; | ||
|
|
||
| beforeEach(() => { | ||
| TestBed.configureTestingModule({ | ||
| // Only the app-level date wiring is registered here. `KbqDatepickerModule` deliberately stays a | ||
| // standalone import of the modal content component, which is where the reported app had it. | ||
| imports: [KbqLuxonDateModule, NoopAnimationsModule, ModalHost], | ||
| providers: [{ provide: KBQ_DATE_FORMATS, useValue: KBQ_LUXON_DATE_FORMATS }] | ||
| }); | ||
|
|
||
| overlayContainer = TestBed.inject(OverlayContainer); | ||
| }); | ||
|
|
||
| afterEach(() => overlayContainer.ngOnDestroy()); | ||
|
|
||
| it('should open the calendar', fakeAsync(() => { | ||
| const fixture = TestBed.createComponent(ModalHost); | ||
|
|
||
| fixture.detectChanges(); | ||
|
|
||
| expect(() => { | ||
| fixture.componentInstance.open(); | ||
| fixture.detectChanges(); | ||
| flush(); | ||
| }).not.toThrow(); | ||
|
|
||
| const toggle = overlayContainer.getContainerElement().querySelector<HTMLElement>('kbq-datepicker-toggle-icon'); | ||
|
|
||
| expect(toggle).not.toBeNull(); | ||
|
|
||
| expect(() => { | ||
| toggle!.click(); | ||
| fixture.detectChanges(); | ||
| tick(500); | ||
| flush(); | ||
| }).not.toThrow(); | ||
|
|
||
| expect(overlayContainer.getContainerElement().querySelector('kbq-datepicker__content')).not.toBeNull(); | ||
| })); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
в прошлый раз мы это добавили, тк тултипы на стакблитз не отображались DS-5007
UPD. стакблитз запускается, ошибок нет