0

First I want to say that I've read many fixes, but noone have fixed my problem.

I'm using this library, https://github.com/amittkSharma/extended-datetimepicker, I need to call a function after my input gets updated.

Examples of how to use the clock can be found in this link, https://rawgit.com/amittkSharma/extended-datetimepicker/master/index.html, this is basically how I'm using the clocks, attaching them to an ng-model.

This library uses a directive, and opens a clock to pick time or date, I'm using it for the time part, I liked this clock very much, so I'm using it. But I cannot find a way to catch the onchange event for my input.

In the directive code there is this comment in line 134, //@TODO custom event to trigger input, which I thought I might add something there, I tried to add an element.on('change') function, but I didn't get it to work, so I'm out of ideas.

I'm using this library to load a bunch a times and make picking time easier. So I need a solution that works like inside on a ng-repeat, or something I can iterate.

Any help would be very much appreciatted.

EDIT

After the answer given by samura, I did some more investigation as to why it wasn't working on my $scope variable.

I didn't mention this, but my $scope variable is an array, and this was the problem (this is why you need to be as detailed as possible when your are asking a question). You need to add a 3rd parameter to watch for changes inside the array, you need to add true.

Like this:

$scope.$watch('timesArray', function() {
    alert('hey, time has changed!');
}, true); //here the 3rd param

Taken from: How to deep watch an array in angularjs?

1 Answer 1

1

For this input

<input mdc-datetime-picker date="false" time="true" type="text" id="time" short-time="true"
           placeholder="Time"
           min-date="minDate"
           format="hh:mm a"
           ng-model="time">

You can use

$scope.$watch('time', function() {
    alert('hey, time has changed!');
});

inside your controller to catch any change on the time property.

Sign up to request clarification or add additional context in comments.

2 Comments

I already tried that, and it did not work.
Ok, your code works perfectly, let me make some edits to my question. Maybe yoy can help a bit more.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.