-
Notifications
You must be signed in to change notification settings - Fork 3
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
refactor (use material2 builds) #6
Conversation
package.json
Outdated
"core-js": "^2.5.1", | ||
"hammerjs": "^2.0.8", | ||
"@angular/animations": "*", | ||
"@angular/cdk": "*", |
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.
Material & CDK 6.0.0-beta.5
is out now which I think should contain your change. You probably want to use that instead of the *-builds
repos. For the rest of the Angular stuff you can use 6.0.0-rc.0
.
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.
@mmalerba Thanks!
Now I get
ERROR in node_modules/@angular/common/src/location/location.d.ts(1,10): error TS2305: Module '"/Users/.../gitreps/JDNConvertibleCalendarDateAdapter/node_modules/rxjs/Rx"' has no exported member 'SubscriptionLike'.
src/app/modules/jdnconvertiblecalendardateadapter/adapter/index.ts(2,57): error TS2305: Module '"/Users/.../gitreps/JDNConvertibleCalendarDateAdapter/node_modules/@angular/material/material"' has no exported member 'MAT_DATE_LOCALE_PROVIDER'.
For error 1 I tried the solution mentioned here https://stackoverflow.com/questions/49446163/typescript-how-to-resolve-rxjs-rx-has-no-exported-member-subscriptionlike but then at runtime it did not work.
For error 2: Was MAT_DATE_LOCALE_PROVIDER
removed from angular/material
?
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.
We have rxjs 6.0.0-beta.1
in our package.json
, you might need to update that too. Yes, we removed MAT_DATE_LOCALE_PROVIDER
in favor of the new scoped injectables (see angular/components#10507). Theoretically this means you can just remove the reference to it
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.
Do I need to update the @types libs?
I get these errors at build time
ERROR in node_modules/@angular/material/table/typings/table-data-source.d.ts(130,5): error TS2416: Property 'connect' in type 'MatTableDataSource<T>' is not assignable to the same property in base type 'DataSource<T>'.
Type '() => BehaviorSubject<T[]>' is not assignable to type '(collectionViewer: CollectionViewer) => Observable<T[]>'.
Type 'BehaviorSubject<T[]>' is not assignable to type 'Observable<T[]>'.
Property 'source' is protected but type 'Observable<T>' is not a class derived from 'Observable<T>'.
node_modules/@angular/material/tree/typings/data-source/flat-data-source.d.ts(80,5): error TS2416: Property 'connect' in type 'MatTreeFlatDataSource<T, F>' is not assignable to the same property in base type 'DataSource<F>'.
Type '(collectionViewer: CollectionViewer) => Observable<F[]>' is not assignable to type '(collectionViewer: CollectionViewer) => Observable<F[]>'. Two different types with this name exist, but they are unrelated.
Type 'Observable<F[]>' is not assignable to type 'Observable<F[]>'. Two different types with this name exist, but they are unrelated.
Property 'source' is protected but type 'Observable<T>' is not a class derived from 'Observable<T>'.
node_modules/@angular/material/tree/typings/data-source/nested-data-source.d.ts(23,5): error TS2416: Property 'connect' in type 'MatTreeNestedDataSource<T>' is not assignable to the same property in base type 'DataSource<T>'.
Type '(collectionViewer: CollectionViewer) => Observable<T[]>' is not assignable to type '(collectionViewer: CollectionViewer) => Observable<T[]>'. Two different types with this name exist, but they are unrelated.
Type 'Observable<T[]>' is not assignable to type 'Observable<T[]>'. Two different types with this name exist, but they are unrelated.
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.
Hmm I'm not sure why that's happening. Here's what our own package.json
looked like as of the 6.0.0-beta.5 release: https://github.com/angular/material2/blob/0e37d6cdd73b49923d06add54e0d34bd9d256eda/package.json
Make sure your dependencies are at a high enough version, delete your package-lock.json
and node_modules/
and then run npm i
. Hopefully that should make it work. (There may be breakages in your code, since these are new major versions, but it should at least get rid of the errors coming from the Angular Material code).
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.
Ok, it works now:-) Thanks!
…tive calendar format
@mmalerba Now this implementation of Once angular/components#10633 is merged, I can use the default header. |
@mmalerba Thanks, I will try with |
src/app/app.component.ts
Outdated
<mat-option *ngFor="let cal of supportedCalendarFormats" [value]="cal">{{cal}}</mat-option> | ||
</mat-select> | ||
</mat-form-field> | ||
<div class="custom-header"> |
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.
@mmalerba If I try to use <mat-calendar-header></mat-calendar-header>
instead I get
compiler.js:215 Uncaught Error: Template parse errors:
No provider for MatCalendar ("
<button mat-icon-button (click)="nextClicked('year')">>></button>
</div>
[ERROR ->]<mat-calendar-header></mat-calendar-header>
"): ng:///AppModule/HeaderComponent.html@13:4
at syntaxError (compiler.js:215)
at TemplateParser.parse (compiler.js:14692)
at JitCompiler._parseTemplate (compiler.js:22632)
at JitCompiler._compileTemplate (compiler.js:22619)
at eval (compiler.js:22562)
at Set.forEach (<anonymous>)
at JitCompiler._compileComponents (compiler.js:22562)
at eval (compiler.js:22472)
at Object.then (compiler.js:206)
at JitCompiler._compileModuleAndComponents (compiler.js:22471)
However, if I use <mat-year-view></mat-year-view>
it works just fine.
I am using 6.0.0-rc.3
.
Is there still something missing to export MatCalendarHeader
? Or is the export you made not included yet in 6.0.0-rc.3
?
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.
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.
/** Default header for MatCalendar */
@Component({
moduleId: module.id,
selector: 'mat-calendar-header',
templateUrl: 'calendar-header.html',
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
})
/**
* An internal component used to display a single year in the datepicker.
* @docs-private
*/
@Component({
moduleId: module.id,
selector: 'mat-year-view',
templateUrl: 'year-view.html',
exportAs: 'matYearView',
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush
})
There is no exportAs
for MatCalendarHeader
. Is that needed to use the selector outside of material?
It should definitely be exported now. The error you're getting doesn't look
like an export problem, it looks like the calendar header is failing to
inject the calendar. This is probably because of the `@Host()`. This is
causing it to only look at the direct parent component, so nesting it
inside another component is not working. Do you want to send a PR removing
the `@Host()` and adding a test case to verify?
You can also add an `exportAs` while you're at it, it's not critical, it's
just so people can do `#header="matCalendarHeader"`, but would be good to
add.
…-Miles
On Fri, Apr 13, 2018 at 8:15 AM Tobias Schweizer ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/app/app.component.ts
<#6 (comment)>
:
> @@ -23,3 +27,87 @@ export class AppComponent {
}
}
+
***@***.***({
+ selector: 'app-calendar-header',
+ template: `
+ <mat-form-field>
+ <mat-select placeholder="Calendar Format" [formControl]="form.controls['calendar']">
+ <mat-option *ngFor="let cal of supportedCalendarFormats" [value]="cal">{{cal}}</mat-option>
+ </mat-select>
+ </mat-form-field>
+ <div class="custom-header">
/** Default header for MatCalendar */
@component({
moduleId: module.id,
selector: 'mat-calendar-header',
templateUrl: 'calendar-header.html',
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
})
/**
* An internal component used to display a single year in the datepicker.
* @docs-private
*/
@component({
moduleId: module.id,
selector: 'mat-year-view',
templateUrl: 'year-view.html',
exportAs: 'matYearView',
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush
})
There is no exportAs for MatCalendarHeader. Is that needed to use the
selector outside of material?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#6 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AOG6SFC9Ywi6KyilNPfUV6PJEmetocAoks5toMEHgaJpZM4S-1Jj>
.
|
Whoops forgot to link to the `@Host` I was talking about, this guy is the
problem I think:
https://github.com/angular/material2/blob/master/src/lib/datepicker/calendar.ts#L50
…On Fri, Apr 13, 2018 at 10:53 AM Miles Malerba ***@***.***> wrote:
It should definitely be exported now. The error you're getting doesn't
look like an export problem, it looks like the calendar header is failing
to inject the calendar. This is probably because of the ***@***.***()`. This is
causing it to only look at the direct parent component, so nesting it
inside another component is not working. Do you want to send a PR removing
the ***@***.***()` and adding a test case to verify?
You can also add an `exportAs` while you're at it, it's not critical, it's
just so people can do `#header="matCalendarHeader"`, but would be good to
add.
-Miles
On Fri, Apr 13, 2018 at 8:15 AM Tobias Schweizer ***@***.***>
wrote:
> ***@***.**** commented on this pull request.
> ------------------------------
>
> In src/app/app.component.ts
> <#6 (comment)>
> :
>
> > @@ -23,3 +27,87 @@ export class AppComponent {
>
> }
> }
> +
> ***@***.***({
> + selector: 'app-calendar-header',
> + template: `
> + <mat-form-field>
> + <mat-select placeholder="Calendar Format" [formControl]="form.controls['calendar']">
> + <mat-option *ngFor="let cal of supportedCalendarFormats" [value]="cal">{{cal}}</mat-option>
> + </mat-select>
> + </mat-form-field>
> + <div class="custom-header">
>
> /** Default header for MatCalendar */
> @component({
> moduleId: module.id,
> selector: 'mat-calendar-header',
> templateUrl: 'calendar-header.html',
> encapsulation: ViewEncapsulation.None,
> changeDetection: ChangeDetectionStrategy.OnPush,
> })
>
> /**
> * An internal component used to display a single year in the datepicker.
> * @docs-private
> */
> @component({
> moduleId: module.id,
> selector: 'mat-year-view',
> templateUrl: 'year-view.html',
> exportAs: 'matYearView',
> encapsulation: ViewEncapsulation.None,
> changeDetection: ChangeDetectionStrategy.OnPush
> })
>
> There is no exportAs for MatCalendarHeader. Is that needed to use the
> selector outside of material?
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <#6 (comment)>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AOG6SFC9Ywi6KyilNPfUV6PJEmetocAoks5toMEHgaJpZM4S-1Jj>
> .
>
|
@mmalerba Ok, I can make a PR for that (angular/components#10856). The CLA is not a problem anymore :-) |
src/app/app.component.ts
Outdated
|
||
this._calendar._dateSelected(convertedDate); | ||
|
||
this._calendar.ngAfterContentInit(); |
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.
After the change of the calendar format, the month view is not updated (today's date is still in the old calendar format and also the new calendar date could be in the previous or next month).
See https://www.dropbox.com/s/mdkp6b5bv76uwsd/month_view.mov?dl=0
If the calendar is toggled, it works. Could the event be triggered from here?
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.
view can be updated using _goToDateInView
, see b1891b3
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.
I assume that these methods are not meant to be exposed to the outside. Should we add them to the public api?
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.
Did you try injecting the ChangeDetectorRef
and calling markForCheck()
?
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.
I can inject it but today's date does not get updated (the circle stays with the old date).
However, if I change the month with the arrow controls (previousClicked
, nextClicked
), it gets updated.
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.
Ah I see, it's because the views only check today's date on init. In that case I think what you're doing should be ok (calling ngAfterContentInit
), even though it looks kind of weird at a glance. I would just put a comment explaining why you're doing it.
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.
Ok, but probably we will need another solution once JDNConvertibleCalendar
supports additional calendar formats that would require a reinit because the amount of months could be different and the names would be different too (e.g., if you convert from Gregorian to Hebrew calendar).
Btw: I will be away for the next two weeks having some time off :-)
Thanks for all your helpful advice:-)
src/app/app.component.ts
Outdated
|
||
// update the calendar UI after date format conversion | ||
// TODO: today's date is not reset correctly | ||
this._calendar.ngAfterContentInit(); |
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.
@mmalerba today's date is still not updated correctly (circle in UI). I would be glad for any suggestions.
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.
see #6 (comment)
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.
I think you need to call init on the various view themselves, rather than the calendar:
let view = this._calendar.currentView == 'month' ? this._calendar.monthView :
(this._calendar.currentView == 'year ? this._calendar.yearView :
this._calendar.multiYearView);
view.ngAfterContentInit();
If you want to send a PR adding a updateTodaysDate()
method to the datepicker, I would be ok with that. This solution seems kind of messy.
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.
Thanks, I will try that!
<mat-select placeholder="Calendar Format" [formControl]="form.controls['calendar']"> | ||
<mat-option *ngFor="let cal of supportedCalendarFormats" [value]="cal">{{cal}}</mat-option> | ||
</mat-select> | ||
<mat-calendar-header></mat-calendar-header> |
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.
@mmalerba This works now :-) (angular/components#10856)
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.
If you want to send a PR adding a updateTodaysDate() method to the datepicker, I would be ok with that. This solution seems kind of messy.
I agree. What about a general method to do a clean reinit? Once we add more calendar formats, the names of the months etc. may be completely different, so we need to reinit the whole thing.
this PR is replaced by #7 |
I want to use material2 builds to implement a calendar switcher (custom header).
I put the github repo in the
package.json
. This creates conflicts with other dependencies. I tried to mark all other third party dependencies with a * to get the latest version.During build I get:
@mmalerba Could you help me here?