bleenco / ng2-datepicker

Angular2 Datepicker Component
http://ng2-datepicker.jankuri.com
MIT License
311 stars 236 forks source link

Only void and foreign elements can be self closed "ng-datepicker" #288

Open azrinsani opened 6 years ago

azrinsani commented 6 years ago

I don't know why.. nothing works!!! so frustrating...

On the screen it says:

ERROR in [at-loader] ./node_modules/ng2-datepicker/src/ng-datepicker/ng-datepicker.component.ts:186:31 TS2345: Argument of type 'Date | undefined' is not assignable to parameter of type 'Date | DatepickerOptions'. Type 'undefined' is not assignable to type 'Date | DatepickerOptions'.

On the console it says:

Only void and foreign elements can be self closed "ng-datepicker"

I use it as follows: <ng-datepicker [(ngModel)]="lastvisited" />

lastvisited is a date variable:

@Input() lastvisited: Date;

jkuri commented 6 years ago

use it as <ng-datepicker [(ngModel)]="lastvisited"></ng-datepicker>. not sure where did you saw Angular components used in self-closed style.

azrinsani commented 6 years ago

Thanks for quick reply! still i am having same problem

on screen it says:

ERROR in [at-loader] ./node_modules/ng2-datepicker/src/ng-datepicker/ng-datepicker.component.ts:186:31 TS2345: Argument of type 'Date | undefined' is not assignable to parameter of type 'Date | DatepickerOptions'. Type 'undefined' is not assignable to type 'Date | DatepickerOptions'.

however, the console error has changed:

ERROR TypeError: Cannot read property 'map' of null at splitDepsDsl (core.es5.js:8712) at _def (core.es5.js:10695) at directiveDef (core.es5.js:10652) at View_AppComponent_Host_0 (AppComponentHost.html:1) at proxyClass (compiler.es5.js:14962) at resolveDefinition (core.es5.js:8756) at ComponentFactory.create (core.es5.js:9859) at ComponentFactoryBoundToModule.create (core.es5.js:3333) at ApplicationRef_.bootstrap (core.es5.js:4768) at core.es5.js:4546

jkuri commented 6 years ago

please check the demo, clone the repository and run it locally.

azrinsani commented 6 years ago

i use the NPM install

jkuri commented 6 years ago

sure, but seems like you are doing something wrong. in this repository you have working example from which you can learn how to get it done right. check https://github.com/bleenco/ng2-datepicker/blob/master/src/components/app-home/app-home.component.html#L10 and https://github.com/bleenco/ng2-datepicker/blob/master/src/components/app-home/app-home.component.ts#L11-L17

azrinsani commented 6 years ago

it says now

ERROR in [at-loader] ./node_modules/ng2-datepicker/src/ng-datepicker/ng-datepicker.component.ts:190:36 TS2532: Object is possibly 'undefined'.

jkuri commented 6 years ago

do you have strict null checks on?

azrinsani commented 6 years ago

i've done this now:

<div class="divTableCell">
    <div *ngIf="date">
        <ng-datepicker [(ngModel)]="date" [options]="options"></ng-datepicker>
    </div>
</div>

but the problem is still occuring

ERROR in [at-loader] ./node_modules/ng2-datepicker/src/ng-datepicker/ng-datepicker.component.ts:186:31 TS2345: Argument of type 'Date | undefined' is not assignable to parameter of type 'Date | DatepickerOptions'. Type 'undefined' is not assignable to type 'Date | DatepickerOptions'.

azrinsani commented 6 years ago

My component class has the following:

export class PersonRowComponent { date: Date; constructor() { this.date = new Date(); } options: DatepickerOptions = { locale: enLocale };

johnwheal commented 6 years ago

@azrinsani Are you using Angular 5? I think this might be an issue introduced in Angular 5.

boban100janovski commented 6 years ago

The example on the home page of the repo says:

Example

<ng-datepicker [(ngModel)]="date" />

Which is not correct

Devarajeshwaran commented 6 years ago

Is there any resolution to this issue? I am getting the same issue as mentioned at the top. I use Angular 4.

vishalhulawale commented 5 years ago

Angular does not allow self-closing for components selectors in default namespace for an unknown reason. But if you change namespace then it works. try this <ns:ng-datepicker [(ngModel)]="date" /> where ns is the name of the custom/foreign namespace.