3

I have this datepicker

http://jsfiddle.net/kevinj/TAeNF/2/

Current has code like this

'use strict';

angular.module('core').directive('jqdatepicker', function () {
    return {
        restrict: 'A',
        require: 'ngModel',
         link: function (scope, element, attrs, ngModelCtrl) {
            element.datepicker({
                dateFormat: 'dd/mm/yy',
                onSelect: function (date) {
                    scope.date = date;
                    scope.$apply();
                }
            });
        }
    };
});

I am using it like this

<input type="text" ng-model="date" jqdatepicker />
<br/>
{{ date }}

My problem is i want to use it in multiple places and they can have different model like

model=date1 , model=date2

Is there any way to make that generic so that it works on model whatever it is attached to rather than hard code

scope.date = date;
4

1 に答える 1