nkalinov / ng2-datetime

Datetime picker plugins wrapper for Angular2+
https://nkalinov.github.io/ng2-datetime
MIT License
157 stars 110 forks source link

Error "No provider for NgControl" #31

Closed chocapic54 closed 8 years ago

chocapic54 commented 8 years ago

Hi everybody ! I got this error "No provider for NgControl!" I'm using the new @angular/forms API with : bootstrap(MyApp, [disableDeprecatedForms(), provideForms()]); And i use datetime like in the demo :

<form #form="ngForm">
    <div class="form-group">
        <datetime name="startDate" [(ngModel)]="date" #startDate="ngModel"></datetime>
    </div>
</form>

And my typescript file :

@Component({
    selector: "edit-event",
    template: require("./editevent.component.html"),
    styles: [require("./calendar.scss")],
    directives: [NKDatetime]
})
export class EditEventComponent {
    date: Date = new Date(2016,3,4);
}

I don't understand why it's happening...

Thanks for your help Chocapic54

EDIT : Got same error when i copy paste demo files into my project

Mielpops54 commented 8 years ago

Hi bro' ! When I try with the demo, I've got the same problem. I don't understand why... it must be due to the new @angular/forms

chocapic54 commented 8 years ago

I've seen that a PR has just been validated by @nkalinov today https://github.com/nkalinov/ng2-datetime/pull/26 But the package has not been yet published to NPM

Do you know when it will @nkalinov ?

josepoma commented 8 years ago

My Component import { NKDatetime } from 'ng2-datetime/ng2-datetime'; import { DatePipe } from '@angular/common'; @Component({ ... directives: [NKDatetime], pipes : [DatePipe] }) export class ParameterListComponent { public parameterFilter : ParameterFilter; constructor(){ this.parameterFilter = new ParameterFilter(); this.parameterFilter.dateEnd = new Date().toISOString().substring(0,10).toString(); }}`

My Page <datetime [(ngModel)]="parameterFilter.dateEnd" NgControl="dateEnd"></datetime>

I have the same problem, is there any solution?

nkalinov commented 8 years ago

closed / c7d8682df4837e578249df0c9f32f66c17ac28ba

neelsbr commented 8 years ago

@nkalinov what was the fix? This issue coming for me after upgrade to 1.1.4. Previously it was fine.

my template code <datetime [(ngModel)]="Purchasedate" [timepicker]="false" [datepicker]="datepickerOpts"></datetime>

chocapic54 commented 8 years ago

can you write us your whole template please ? In my case, update to 1.1.4 has solved this issue

neelsbr commented 8 years ago

`<form (ngSubmit)="createorder(buyForm.value)" #buyForm="ngForm" >

Purchase Date is required
            </div>

`

FYI I am using old forms API

rafalkasa commented 8 years ago

Hi @neelsbr

If you are using previous version of the @angular/forms you should use previous version of ng2-datetime or upgrade your project to @angular/forms 0.2.0.

I recomend to you upgrade your project to new version of forms, as I suppose @nkalinov doesn't have in plan support previous version of @angular/forms also as Google in next angular2 releases.

wartab commented 8 years ago

There is a reason the old forms are going to be deprecated. I strongly advise you to switch as soon as you can, only for the sake of your Angular2 lib's stability.

@rafalkasa's fix did it for me.

neelsbr commented 8 years ago

thanks @rafalkasa @wartab @nkalinov for your response. Let me update forms API

mikedodd commented 8 years ago

im having the same problem on the latest version for forms 0.2.0

raghubala commented 8 years ago

any solution. running into the same issue e.rror "No provider for NgControl"

chocapic54 commented 8 years ago

I'am currently not running this error with the last version of ng2-datetime and with angular@2.0.1

Droxx commented 7 years ago

I'm still seeing this issue on angular@2.1.0

marvincenzi commented 7 years ago

Me too, seeing this issue on angular@2.1.2

Droxx commented 7 years ago

I managed to solve this issue. I was using the component in two locations and only one was throwing the error.

Turns out the one that was causing issues. I was not binding to [(ngModel)]. And only using the event. Try binding to [(ngModel)] and see if that helps.

hardy12994 commented 7 years ago

I am also getting this error No provider for NgControl Have anyone got the Solution ?

impankratov commented 6 years ago

Another solution is to use the @Optional() decorator. More on that here: https://stackoverflow.com/a/48156981/6673479