2016-07-27 72 views
0

我从AngularJs开始。在AngularJs中实现bootstrap-datepicker

我需要在窗体中实现“N”个日历。我使用的自举日期选择器(https://eonasdan.github.io/bootstrap-datetimepicker/

,如果我指定的inputTextId例如

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"> 

控制器:

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

它工作正常的一个inputText,如果我想在多个实现它,我必须指定每个名称和功能。我想通过参考和使用:

reference.datepicker();或类似的东西,以创建一个功能。 这可能吗?

+0

使用:[** angular-ui#datepicker **](https://angular-ui.github.io/bootstrap/#/datepicker) – developer033

+0

为什么使用jquery $(“#datetimepicker2”)。在角度项目,它不是一个很好的做法,你必须使用角度指令,ref http://jsfiddle.net/cletourneau/kGGCZ/或http://plnkr.co/edit/KsK5F1M2zrv0SDTwRM4N?p=preview –

回答

1

听起来像你想要一个指令。以此为例子:

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

你会那么只需添加time-picker到你想要的输入。