0

I am starting with AngularJs.

I need to implement "N" Calendars in a form. I am using bootstrap-datepicker (https://eonasdan.github.io/bootstrap-datetimepicker/)

It is working fine if I specify the inputTextId for example

Html:

<input id='datetimepicker2' data-ng-model="vm.search.origin.from" data-ng-click="vm.showCalendar(this)" class="form-control" type="text" placeholder="MM/DD HH:MM">

<input data-ng-model="vm.search.origin.to" data-ng-click="vm.showCalendar(this)" class="form-control" type="text" placeholder="MM/DD HH:MM">

Controller:

function showCalendar(obj)
{
    $("#datetimepicker2").datetimepicker();
}

It works fine for one inputText, and if I want to implement it in more than one I have to specify every name and function. I want to pass the reference and use:

reference.datepicker(); or something like that in order to create just one function. Is that possible?

2

1 Answer 1

1

Sounds like you want a directive. Take this as an example:

app.directive('timePicker', function() {
    return {
        link: function($scope, elem, attrs){
          $(elem).datetimepicker();
        }
    }
});

You would then just add time-picker to the inputs you want.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.