g00fy- / angular-datepicker

calendar and datepicker directives for angular
MIT License
719 stars 420 forks source link

Date/time selection is not available in $scope? #127

Open spryce opened 9 years ago

spryce commented 9 years ago

Feel free to correct me if I'm using this incorrectly or if there is a better way to do things. I'm fairly new to Angular.

I've tried to implement this in a project using <input type="datetime" date-time ng-model="start"> and I see a couple of issues here.

Firstly the selected date/time is not made available to the page $scope, and secondly this seems a little misleading because in the markup we can see ng-model="start" but this is isolated.

On the first note: I'm currently getting the value of the datepicker by giving it an id and using myDate = angular.element("#datePicker")[0].value which works fine but doesnt seem very angular. Is this the best way to get this value? If this value was made available to the page scope by going $scope.datePicker.startDate or similar this would be much cooler.

Second: ng-model="start" feels to me like it should be in the template. Being in the mark up makes me think its available to page scope and I will have accesss to the selected value from the input/datepicker. I havent tried using <div date-range start="start" end="end"></div> but Im guessing these values are also not available? Would it be better to load a template dynamically based on if you only want a start or both a start and end date, and move these isolated scope values to the respective templates?

Finally maybe I can help on this project? It would be my first github contribution but if I can find time this looks like a pretty cool place to start.

Cheers

spryce commented 9 years ago

Just another thought. Being that there is no page scope model for this directive there doesnt seem to be a way to pass it a date/time on page load?

e.g. I have a web service that passes data to my page but I cant autofill/preselect the datepicker value.

Am I missing something or is this another feature that we can add? Ta...

eralha commented 9 years ago

Since date-time directive have its own isolated scope it will not update its parent scope, so you need to access the value through the form.value http://plnkr.co/edit/OsP3uGYGK5hYEPuwgynS

If you would like to contribute, feel free to propose changes and send PR.

saracen7 commented 9 years ago

Agree with Spryce. Being able to pass it a date/time value on load would be great.

ggondim commented 9 years ago

I am using this component as a part of the WrapBootstrap's Inspinia Theme, and I came here when I found that the datepicker doesn't updates the $scope.

Well, opinions apart, I think the $scope update is a BASIC feature needed to launch a project. I am not criticizing you, guys, but it is a thing that really needs to be implemented in a plugin made for Angular.

As my suggestion, if the directive has its own isolated scope, to implement this feature, a simple $scope.emit() from inside directive wouldn't satisfy this issue?