I defined a directive like this:
angular.module('MyModule', []) .directive('datePicker', function($filter) { return { require: 'ngModel', link: function(scope, elem, attrs, ctrl) { ctrl.$formatters.unshift(function(modelValue) { console.log('formatting',modelValue,scope,elem,attrs,ctrl); return $filter('date')(modelValue, 'MM/dd/yyyy'); }); ctrl.$parsers.unshift(function(viewValue) { console.log('parsing',viewValue); var date = new Date(viewValue); return isNaN(date) ? '' : date; }); } } });
What I applied to an element like this:
<input type="text" date-picker="MM/dd/yyyy" ng-model="clientForm.birthDate" />
My directive is triggered when I add a date-picker attribute to an element, but I want to know how to access the attribute value ( MM/dd/yyyy ) inside my JS directive so that I can remove this constant next to $filter , I donโt sure if i have any variable i have access to this.
angularjs
mpen Jan 24 '13 at 4:41 2013-01-24 04:41
source share